![]() You might also take a look at plt.figlegend(). Have a look at the matplotlib legend guide. # Shrink current axis's height by 10% on the bottomĪx.set_position([box.x0, box.y0 + box.height * 0.1,Īx.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), Figure labels: suptitle, supxlabel, supylabel. # Put a legend to the right of the current axisĪx.legend(loc='center left', bbox_to_anchor=(1, 0.5))Īnd in a similar manner, shrink the plot vertically, and put a horizontal legend at the bottom: import matplotlib.pyplot as plt Line, = ax.plot(x, i * x, label='$y = %ix$'%i)Īx.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),Īlternatively, shrink the current plot's width, and put the legend entirely outside the axis of the figure (note: if you use tight_layout(), then leave out ax.set_position(): import matplotlib.pyplot as pltĪx.set_position() Similarly, make the legend more horizontal and/or put it at the top of the figure (I'm also turning on rounded corners and a simple drop shadow): import matplotlib.pyplot as plt If we do the same thing, but use the bbox_to_anchor keyword argument we can shift the legend slightly outside the axes boundaries: import matplotlib.pyplot as plt So, let's start with a generic example: import matplotlib.pyplot as plt The enumerate (axs.flatten ()) function is used to iterate over each subplot (or ‘axes’), and the ax.hist (data i) function is used to plot a histogram of the i-th dataset on the i-th subplot. To add to what and already said, you can use the bbox_to_anchor keyword argument to place the legend partially outside the axes and/or decrease the font size.īefore you consider decreasing the font size (which can make things awfully hard to read), try playing around with placing the legend in different places: In this code, plt.subplots (2, 2, figsize (10, 10)) creates a 2x2 grid of subplots. See this answer for usage example.Īll of which accept string sizes or 'normal' (400), 'bold' (700), 'lighter', and 'bolder' ( relative with respect to current weight).There are a number of ways to do what you want. How to Add Title to Subplots in Matplotlib D deepanshurustagi Read Discuss Courses Practice In this article, we will see how to add a title to subplots in Matplotlib Let’s discuss some concepts : Matplotlib : Matplotlib is an amazing visualization library in Python for 2D plots of arrays. ![]() We can also add figure-level x- and y-labels using FigureBase.supxlabel and FigureBase.supylabel.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |