format_date_axis

ssapy.plotUtils.format_date_axis(time_array, ax)[source][source]

Format the x-axis of a plot with time-based labels depending on the span of the time array.

Parameters: - time_array (array-like): An array of time objects (e.g., astropy.time.Time) to be used for the x-axis labels. - ax (matplotlib.axes.Axes): The matplotlib axes object on which to set the x-axis labels.

Returns: None

This function formats the x-axis labels of a plot based on the span of the provided time array. The labels are set to show either hours and day-month or month-year formats, depending on the time span.

The function performs the following steps: 1. If the time span is less than one month:

  • If the time span is less than a day, the labels show ‘HH:MM dd-Mon’.

  • Otherwise, the labels show ‘dd-Mon-YYYY’.

  1. If the time span is more than one month, the labels show ‘Mon-YYYY’.

The function selects six nearly evenly spaced points in the time array to set the x-axis labels.

Example usage: ``` import matplotlib.pyplot as plt from astropy.time import Time import numpy as np

# Example time array time_array = Time([‘2024-07-01T00:00:00’, ‘2024-07-01T06:00:00’, ‘2024-07-01T12:00:00’,

‘2024-07-01T18:00:00’, ‘2024-07-02T00:00:00’])

fig, ax = plt.subplots() ax.plot(time_array.decimalyear, np.random.rand(len(time_array))) format_date_axis(time_array, ax) plt.show() ```