handles: a list of artists (lines, patches) to be added to the.Parent: the artist that contains the legend Loc can be a tuple of the normalized coordinate values with 'best' : 0, (only implemented for axis legends) Sequence of strings and loc can be a string or an integer Place a legend on the axes at location loc. Legend ( parent, handles, labels, loc=None, numpoints=None, markerscale=None, scatterpoints=None, scatteryoffsets=None, prop=None, fontsize=None, borderpad=None, labelspacing=None, handlelength=None, handleheight=None, handletextpad=None, borderaxespad=None, columnspacing=None, ncol=1, mode=None, fancybox=None, shadow=None, title=None, framealpha=None, bbox_to_anchor=None, bbox_transform=None, frameon=None, handler_map=None ) ¶ artist_picker ( legend, evt ) ¶ finalize_offset ( ) ¶ class matplotlib.legend. If “bbox”, updateībox_to_anchor parameter. Update : If “loc”, update loc parameter of DraggableLegend ( legend, use_blit=False, update=u'loc' ) ¶īases: See the legend guideįor more information. Note that not all kinds of artist are supported by the legend yet by defaultīut it is possible to extend the legend handler’s capabilities to Handlers are defined in the legend_handler module). Plot elements and the legend handlers to be used (the default legend Specified by the handler map, which defines the mapping between the Plot elements in the axes or figures (e.g., lines, patches, etc.) are Creation of corresponding legend handles from the The Legend class can be considered as a container of legend handlesĪnd legend texts. Most users would normally create a legend via the In this code, the hist function creates the histogram and the legend function adds the legend to the histogram.It is unlikely that you would ever create a Legend instance manually. We also passed the property with a size of 15. Then we called the legend() function for setting the legend. The x array is passed as the required argument then we have passed a number of bins as 10 then we have passed density as True then we have passed the color as colr array. Then we created a list that is stored in three colors called blue orange and green. Then we have assigned the number of bins as 10. Then we created a random array and stored it in x. Then we have imported numpy for creating random coordinates. The matplotlib library consists of all the functions for plotting different types of graphs. In this program, we imported matplotlib.pyplot for plotting the histogram and adding a legend to it. Plt.title('Histogram Example', fontweight="bold") N, bins, patches = plt.hist(x, num_bins, density=True, color=colr) # random numbers are created and stored in x variable Program for creating a histogram and then plotting the legends for the histogram using Then we have displayed the graph using the show function. We have placed the legend in the center-right position. Then we placed the legend with labels blue and orange on the graph. Finally, the plot function plots the points into the graph. Then we plotted the lines using the plot function. Then, we imported numpy to create two arrays for plotting the lines. In this program, we imported matplotlib.pyplot for plotting two lines. # displaying the created graph using the show method Program for creating the legend using ī = np.array() The matplotlib.lengend() function returns the legend for the graph. The color given in this argument is kept as the background color for the Legend.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |