Fix #160: Improve default time axis formatting using ConciseDateFormatter#163
Fix #160: Improve default time axis formatting using ConciseDateFormatter#163Amityush-lgtm wants to merge 5 commits intosunpy:mainfrom
Conversation
|
I was unsatisfied with my current approach in using native datetime since we have to manually convert when using
@samaloney, Let me know your thoughts on this, which one should i prefer or any other alternatives you have. Happy to make changes! |
|
Those plots look much better! So it sounds like there is an incompatibly between the adapter approach sounds interesting would try to hook into the If you do try this just make sure to not remove the commits for this working approach above so it would be easy to compare. |
…onciseDateFormatter
|
@samaloney I have implemented the |
|
I haven't forgotten this will have another look at this later this week. |
There was a problem hiding this comment.
Pull request overview
This PR addresses #160 by improving spectrogram time-axis labeling, switching the default x-axis formatting to Matplotlib’s date locator/formatter machinery for more readable, concise time ticks while preserving support for setting limits with both astropy.time.Time and datetime.
Changes:
- Added a shared
_TimeAxisMixinand a custom Matplotlib date converter to supportastropy.time.Timeinputs on the x-axis. - Updated
PcolormeshPlotMixin.plot()andNonUniformImagePlotMixin.plotim()to plot using Matplotlib date-number values and applyAutoDateLocator+ConciseDateFormatter. - Expanded test coverage to validate date conversion behavior, axis limit compatibility, leap-second handling, formatter selection, and x-label content.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
radiospectra/spectrogram/tests/test_spectrogrambase.py |
Adds/updates tests asserting plot-date conversion, set_xlim compatibility (Time/datetime), leap-second handling, and ConciseDateFormatter usage. |
radiospectra/mixins.py |
Introduces _TimeAxisMixin plus a Time-aware DateConverter, and updates plotting to use plot_date + concise time-axis formatting. |
changelog/163.feature.rst |
Adds a news fragment describing the improved default time-axis formatting behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.


PR Description
Fixes #160
This PR improves the default time axis formatting for spectrogram plots by introducing Matplotlib's
ConciseDateFormatterandAutoDateLocatorfor more readable and concise time labels on the x-axis.What Changed:
_TimeAxisMixininradiospectra/mixins.pyto share time axis setup logic between different plotting methods.datetimeobjects before plotting. This allows Matplotlib to use its built-inConciseDateFormatterandAutoDateLocatornatively.PcolormeshPlotMixin.plot()andNonUniformImagePlotMixin.plotim()to use the new mixin and datetime-based plotting.Visual Proofs:
AI Assistance Disclosure
AI tools were used for:
Note:
For the code given in the #58 (comment), there was a slight change made in the code for using
datetime:axes.set_xlim(Time("2020-07-11T02:15").datetime, Time("2020-07-11T02:50").datetime)@samaloney, Let me know your thoughts on this! Happy to make changes.