Skip to content

Commit

Permalink
fix: ts plot x axis date format
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarros committed Aug 6, 2024
1 parent 9771fb1 commit a01f5ae
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/ydata_profiling/visualisation/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,14 @@ def _format_ts_date_axis(
axis: matplotlib.axis.Axis,
) -> matplotlib.axis.Axis:
if isinstance(series.index, pd.DatetimeIndex):
locator = AutoDateLocator()
axis.xaxis.set_major_locator(locator)
axis.xaxis.set_major_formatter(ConciseDateFormatter(locator))
ax_bak = copy.deepcopy(axis)
try:
locator = AutoDateLocator()
axis.xaxis.set_major_locator(locator)
axis.xaxis.set_major_formatter(ConciseDateFormatter(locator))
axis.xaxis.get_major_ticks()
except Exception:
axis = ax_bak

return axis

Expand Down Expand Up @@ -592,7 +597,6 @@ def plot_timeseries_gap_analysis(
label=label,
color=color,
alpha=0.65,
x_compat=True,
)
_format_ts_date_axis(serie, ax)
ax.yaxis.set_major_locator(MaxNLocator(integer=True))
Expand Down Expand Up @@ -678,11 +682,11 @@ def _plot_timeseries(
colors = create_comparison_color_list(config)

for serie, color, label in zip(series, colors, labels):
ax = serie.plot(color=color, label=label, alpha=0.75, x_compat=True)
ax = serie.plot(color=color, label=label, alpha=0.75)
_format_ts_date_axis(serie, ax)

else:
ax = series.plot(color=config.html.style.primary_colors[0], x_compat=True)
ax = series.plot(color=config.html.style.primary_colors[0])
_format_ts_date_axis(series, ax)

return plot
Expand Down

0 comments on commit a01f5ae

Please sign in to comment.