![]() ![]() However, to change the location of a legend in Matplotlib. We can put the legend ouside by resizing the box and puting the legend relative to that:Īx.set_position()Īx.legend(loc= 'upper center', bbox_to_anchor=( 1.45, 0.8), shadow= True, ncol= 1)Īx.legend(loc= 'upper center', bbox_to_anchor=( 1.45, 0. By default, Matplotlib places the legend at the best location that does not overlap with the plot. To put the legend on top, change the bbox_to_anchor values:Īx.legend(loc= 'upper center', bbox_to_anchor=( 0.5, 1.00), shadow= True, ncol= 2)Īx.legend(loc= 'upper center', bbox_to_anchor=( 0.5, 1.00), shadow= True, ncol= 2) Take into account that we set the number of columns two ncol=2 and set a shadow. To place the legend on the bottom, change the legend() call to:Īx.legend(loc= 'upper center', bbox_to_anchor=( 0.5, - 0.05), shadow= True, ncol= 2) If I label them like this, I only receive the list several times in the legend, instead of the right ticker for each line. ![]() In df2plot is a list of tickers that is delivered, so more lines and more tickers within legend. Adding the legend: To add a legend to a particular subplot, use the legend() function with the desired location and additional parameters, such as the font. One graph is just one line, so no problem with labeling the legend. Y2 = Īx.plot(x, y2, label= '$y2 = other numbers') I want to plot 2 different graphs in one plot. The legend location can be set explicitly to a particular place using the loc. To place the legend inside, simply call legend(): The plotting functions within Matplotlib are found within the pyplot. Not sure what would be the best way to expose this. Of course, this needs some knowledge of matplotlib internals and will be difficult for normal users. In principle, you can change 'ncol' within a legend by manually rearranging these offsetboxes. ![]() My actual case includes an arbitrary number of series specified with a widget. Legend in matplotlib is a collection of OffsetBox. I do not mean the text of the legend like described in the post Matplotlib legend vertical rotation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |