.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/general/plot_lineplot_with_legend.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_generated_gallery_general_plot_lineplot_with_legend.py: Multi-Line Temperature Profile Plot =================================== .. GENERATED FROM PYTHON SOURCE LINES 6-49 .. image-sg:: /generated/gallery/general/images/sphx_glr_plot_lineplot_with_legend_001.png :alt: Air temperature :srcset: /generated/gallery/general/images/sphx_glr_plot_lineplot_with_legend_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import iris import iris.plot as iplt import iris.quickplot as qplt def main(): fname = iris.sample_data_path("air_temp.pp") # Load exactly one cube from the given file. temperature = iris.load_cube(fname) # We only want a small number of latitudes, so filter some out # using "extract". temperature = temperature.extract( iris.Constraint(latitude=lambda cell: 68 <= cell < 78) ) for cube in temperature.slices("longitude"): # Create a string label to identify this cube (i.e. latitude: value). cube_label = "latitude: %s" % cube.coord("latitude").points[0] # Plot the cube, and associate it with a label. qplt.plot(cube, label=cube_label) # Add the legend with 2 columns. plt.legend(ncol=2) # Put a grid on the plot. plt.grid(True) # Tell matplotlib not to extend the plot axes range to nicely # rounded numbers. plt.axis("tight") # Finally, show it. iplt.show() if __name__ == "__main__": main() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.116 seconds) .. _sphx_glr_download_generated_gallery_general_plot_lineplot_with_legend.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_lineplot_with_legend.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_lineplot_with_legend.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_