.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples\matplotlib\draw_span.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_matplotlib_draw_span.py: draw a span =========== .. GENERATED FROM PYTHON SOURCE LINES 5-26 .. image-sg:: /auto_examples/matplotlib/images/sphx_glr_draw_span_001.png :alt: draw span :srcset: /auto_examples/matplotlib/images/sphx_glr_draw_span_001.png :class: sphx-glr-single-img .. code-block:: default from pylab import * from matplotlib import lines from matplotlib.transforms import IdentityTransform fig, (ax1,ax2,ax3,ax4) = subplots(4,1, figsize=(4,4)) subplots_adjust(left=0.2) def draw_span(ax1, ax2, label, allow_for_text=10, allow_for_ticks=40): x1,y1 = ax1.transAxes.transform(r_[0,1]) x2,y2 = ax2.transAxes.transform(r_[0,0]) x1-=allow_for_ticks x_text = x1-allow_for_text x2-=allow_for_ticks x1,y1 = fig.transFigure.inverted().transform(r_[x1,y1]) x_text,_ = fig.transFigure.inverted().transform(r_[x_text,0]) x2,y2 = fig.transFigure.inverted().transform(r_[x2,y2]) lineA = lines.Line2D([x1,x2],[y1,y2], linewidth=3, color='r', transform=fig.transFigure, clip_on=False) text(x_text, (y2+y1)/2, label, va='center', ha='right', rotation=90, transform=fig.transFigure, color='r') fig.add_artist(lineA) draw_span(ax1,ax3,"a label") show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.085 seconds) .. _sphx_glr_download_auto_examples_matplotlib_draw_span.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: draw_span.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: draw_span.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_