Skip to content

Better date axes#68

Open
phil-brad wants to merge 5 commits into
masterfrom
feature/heatmap-date-ticks
Open

Better date axes#68
phil-brad wants to merge 5 commits into
masterfrom
feature/heatmap-date-ticks

Conversation

@phil-brad
Copy link
Copy Markdown
Member

When all values of an axis are datetimes, then use the matplotlib concise date formatter for a nice date axis.

Copilot AI review requested due to automatic review settings May 22, 2026 20:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves matplotlib axis tick formatting by detecting when axis labels are datetime-like and switching to Matplotlib’s concise date formatting to produce more readable date axes.

Changes:

  • Added datetime-axis detection for x_labels/y_labels and introduced date-specific tick generation/formatting helpers.
  • Updated tick rotation/alignment handling for the x-axis.
  • Initialized grid line state during widget construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

self._setting_axis_limits = False

self.hasHiddenSeries = False
self._do_update_grid_lines(self._axes)
Comment on lines 873 to +877
if hasattr(self.data, 'x_labels'):
step = self.data.x_tick_interval if hasattr(self.data, 'x_tick_interval') else None
x_ticks, x_labels, x_ticks_rotation = self._get_labels(self.data.x_labels, step, horizontal=True)
self._axes.set_xticks(x_ticks)
if all(isinstance(x, (np.datetime64, pd.Timestamp)) for x in self.data.x_labels):
x_labels = self.data.x_labels
self._update_date_xticks(x_labels)
x_ticks_rotation = 0.0
Comment thread pyqttoolkit/views/plot/matplotlib/base.py
self._axes.xaxis.set_tick_params(labelrotation=rotation)
matplotlib.artist.setp(self._axes.get_xticklabels(),
horizontalalignment='right' if rotation else 'center')
self._adjust_to_xticklabels_height(self._axes.get_xticklabels(), rotation)

locator = mdates.AutoDateLocator(maxticks=min(imax - imin, 25))
offset_formats = ['', '%Y', '%Y-%b', '%Y-%b', '%Y-%m-%d', '%Y-%m-%d']
formatter = mdates.ConciseDateFormatter(axis_obj.get_major_locator(),
Comment on lines +951 to +955
locator = mdates.AutoDateLocator(maxticks=min(imax - imin, 25))
offset_formats = ['', '%Y', '%Y-%b', '%Y-%b', '%Y-%m-%d', '%Y-%m-%d']
formatter = mdates.ConciseDateFormatter(axis_obj.get_major_locator(),
offset_formats=offset_formats)

Comment on lines +947 to +955
e0, e1 = extent
imin, imax = max(0, math.floor(e0)), min(math.ceil(e1), len(labels) - 1)
date_num_min, date_num_max = mdates.date2num(labels[0]), mdates.date2num(labels[-1])

locator = mdates.AutoDateLocator(maxticks=min(imax - imin, 25))
offset_formats = ['', '%Y', '%Y-%b', '%Y-%b', '%Y-%m-%d', '%Y-%m-%d']
formatter = mdates.ConciseDateFormatter(axis_obj.get_major_locator(),
offset_formats=offset_formats)

self._axes.set_yticks(y_ticks)
self._axes.set_yticklabels(y_labels)
self._adjust_to_yticklabels_width(y_labels)
if all(isinstance(y, (np.datetime64, pd.Timestamp)) for y in self.data.y_labels):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants