![]() ![]() 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. 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. The prime minister and chancellor both insist the government's plan to tackle inflation is the right one, despite the Bank of England raising interest rates to 5. 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) Y2 = Īx.plot(x, y2, label= '$y2 = other numbers') To place the legend inside, simply call legend(): Data Visualization with Matplotlib and Python In some cases, it is not possible to set the label of the handle, so it is possible to pass through the list of labels to legend (): lineup, plt.plot( 1,2,3, label'Line 2') linedown, plt.plot( 3,2,1, label'Line 1') plt.legend( lineup, linedown, 'Line Up', 'Line Down') Creating artists specifically for adding to the legend (aka. In some cases, it is not possible to set the label of the handle, so it is possible to pass through the list of labels to legend(): fig, ax plt.In this article we will show you some examples of legends using matplotlib. The legend() method adds the legend to the plot. Legends can be placed in various positions: A legend can be placed inside or outside the chart and the position can be moved. Its basically using a list of legend handles to make one of the markers of the first handle invisible and overplot it with the marker of the second handle. Matplotlib has native support for legends. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |