.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/lines_bars_and_markers/linestyles.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. 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_gallery_lines_bars_and_markers_linestyles.py: ========== Linestyles ========== Simple linestyles can be defined using the strings "solid", "dotted", "dashed" or "dashdot". More refined control can be achieved by providing a dash tuple ``(offset, (on_off_seq))``. For example, ``(0, (3, 10, 1, 15))`` means (3pt line, 10pt space, 1pt line, 15pt space) with no offset, while ``(5, (10, 3))``, means (10pt line, 3pt space), but skip the first 5pt line. See also `.Line2D.set_linestyle`. *Note*: The dash style can also be configured via `.Line2D.set_dashes` as shown in :doc:`/gallery/lines_bars_and_markers/line_demo_dash_control` and passing a list of dash sequences using the keyword *dashes* to the cycler in :ref:`property_cycle `. .. GENERATED FROM PYTHON SOURCE LINES 18-76 .. image-sg:: /gallery/lines_bars_and_markers/images/sphx_glr_linestyles_001.png :alt: Named linestyles, Parametrized linestyles :srcset: /gallery/lines_bars_and_markers/images/sphx_glr_linestyles_001.png, /gallery/lines_bars_and_markers/images/sphx_glr_linestyles_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np linestyle_str = [ ('solid', 'solid'), # Same as (0, ()) or '-' ('dotted', 'dotted'), # Same as (0, (1, 1)) or ':' ('dashed', 'dashed'), # Same as '--' ('dashdot', 'dashdot')] # Same as '-.' linestyle_tuple = [ ('loosely dotted', (0, (1, 10))), ('dotted', (0, (1, 1))), ('densely dotted', (0, (1, 1))), ('long dash with offset', (5, (10, 3))), ('loosely dashed', (0, (5, 10))), ('dashed', (0, (5, 5))), ('densely dashed', (0, (5, 1))), ('loosely dashdotted', (0, (3, 10, 1, 10))), ('dashdotted', (0, (3, 5, 1, 5))), ('densely dashdotted', (0, (3, 1, 1, 1))), ('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))), ('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))), ('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))] def plot_linestyles(ax, linestyles, title): X, Y = np.linspace(0, 100, 10), np.zeros(10) yticklabels = [] for i, (name, linestyle) in enumerate(linestyles): ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black') yticklabels.append(name) ax.set_title(title) ax.set(ylim=(-0.5, len(linestyles)-0.5), yticks=np.arange(len(linestyles)), yticklabels=yticklabels) ax.tick_params(left=False, bottom=False, labelbottom=False) ax.spines[:].set_visible(False) # For each line style, add a text annotation with a small offset from # the reference point (0 in Axes coords, y tick value in Data coords). for i, (name, linestyle) in enumerate(linestyles): ax.annotate(repr(linestyle), xy=(0.0, i), xycoords=ax.get_yaxis_transform(), xytext=(-6, -12), textcoords='offset points', color="blue", fontsize=8, ha="right", family="monospace") fig, (ax0, ax1) = plt.subplots(2, 1, figsize=(10, 8), height_ratios=[1, 3]) plot_linestyles(ax0, linestyle_str[::-1], title='Named linestyles') plot_linestyles(ax1, linestyle_tuple[::-1], title='Parametrized linestyles') plt.tight_layout() plt.show() .. _sphx_glr_download_gallery_lines_bars_and_markers_linestyles.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: linestyles.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: linestyles.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_