
python - Adding a matplotlib legend - Stack Overflow
You can access the Axes instance (ax) with plt.gca().In this case, you can use. plt.gca().legend() You can do this either by using the label= keyword in each of your plt.plot() calls or by assigning your labels as a tuple or list within legend, as in this working example:
python - How to manually create a legend - Stack Overflow
For those wanting to add manual legend items into a single/common legend with automatically generated items: #Imports import matplotlib.patches as mpatches # where some data has already been plotted to ax handles, labels = ax.get_legend_handles_labels() # manually define a new patch patch = mpatches.Patch(color='grey', label='Manual Label') # handles is a list, so …
How to modify matplotlib legend after it has been created?
Jan 23, 2015 · You could check matplotlib.legend.Legend.__init__ to see how and why it's done. The extra condition on the fontsize parameter is used for overriding the font size when the legend was originally created with a prop , as prop usually overwrites fontsize .
How do you create a legend for a contour plot? - Stack Overflow
Jun 3, 2022 · You could also do it directly with the lines of the contour, without using proxy artists. import matplotlib import numpy as np import matplotlib.cm as cm import matplotlib.mlab as mlab import matplotlib.pyplot as plt matplotlib.rcParams['xtick.direction'] = 'out' matplotlib.rcParams['ytick.direction'] = 'out' delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = …
matplotlib - Python legend in 3dplot - Stack Overflow
Jan 18, 2016 · But I don't want to have duplicate legend entries instead . I want my legend entries to group with colour, or ; Is it possible have both marker and line as a single entry so that there are only 5 entries in my legend; I found a similar question to this (How to make custom legend in matplotlib) but it does not solve my problem
python - Matplotlib legend for an arrow - Stack Overflow
Nov 6, 2015 · I would like to know how it is possible to label an arrow and show it in the legend of a plot. For instance if I do this. arrow(0,1,'dummy',label='My label') legend() I do not see anything in the legend. I would like to see in the legend box an arrow next to its label.
How display a legend of an arrow created with quiver?
Jun 8, 2017 · How can I put the legend of arrows drawn using pyplot.quiver or pyplt.annotate methods? I'm currently using the following code: import matplotlib.pyplot as plt from numpy.random import * x, y =...
python - Multi-color Legend Entry - Stack Overflow
May 11, 2023 · I would like to make a legend entry in a matplotlib look something like this: It has multiple colors for a given legend item. Code is shown below which outputs a red rectangle. I'm wondering what I...
python - How to put the legend outside the plot - Stack Overflow
A figure legend. One may use a legend to the figure instead of the axes, matplotlib.figure.Figure.legend. This has become especially useful for Matplotlib version 2.1 or later, where no special arguments are needed. fig.legend(loc=7) to create a legend for all artists in the different axes of the figure.
python - Matplotlib Legends in For Loop - Stack Overflow
Dec 10, 2015 · matplotlib; legend; Share. asked Dec 10, 2015 at 21:50. DJV DJV. 873 4 4 gold badges 15 15 silver badges ...