.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/line_plots/time_axis_locators.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_line_plots_time_axis_locators.py: Datetime axis with monthly majors and weekly minors =================================================== Configure a time-aware x-axis entirely through EMCPy: - Monthly major ticks with labels (e.g., "Oct 2024") - Weekly minor ticks - Rotated, right-aligned labels .. GENERATED FROM PYTHON SOURCE LINES 10-39 .. image-sg:: /examples/line_plots/images/sphx_glr_time_axis_locators_001.png :alt: Datetime axis (monthly majors, weekly minors) :srcset: /examples/line_plots/images/sphx_glr_time_axis_locators_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt import datetime as dt from emcpy.plots.plots import LinePlot from emcpy.plots.create_plots import CreatePlot, CreateFigure start = dt.datetime(2024, 10, 1) dates = np.array([start + dt.timedelta(days=i) for i in range(170)]) y = 10 + np.sin(np.linspace(0, 6*np.pi, dates.size)) + 0.2*np.random.randn(dates.size) p = CreatePlot() lp = LinePlot(dates, y) lp.linewidth = 1.8 lp.label = "series" p.plot_layers = [lp] p.add_title("Datetime axis (monthly majors, weekly minors)") p.add_ylabel("value") p.add_grid() # EMCPy time-axis helper applies locators/formatter/rotation p.set_time_axis(major="month", minor="week", fmt="%b %Y", rotate=30, ha="right") p.add_legend(loc="upper right", frameon=False) fig = CreateFigure(nrows=1, ncols=1, figsize=(8.5, 4)) fig.plot_list = [p] fig.create_figure() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.119 seconds) .. _sphx_glr_download_examples_line_plots_time_axis_locators.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: time_axis_locators.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: time_axis_locators.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: time_axis_locators.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_