![]() ![]() ![]() Despite this, numerous edits recently have insisted on putting these in, often in ways that led to the code raising an error. The intent of this question was to completely avoid the use of arbitrary coordinate placements of arbitrary text as was the traditional solution to these problems. Text = ax.text(-0.2,1.05, "Aribitrary text", transform=ax.transAxes)įig.savefig('samplefigure', bbox_extra_artists=(lgd,text), bbox_inches='tight') Lgd = ax.legend(handles, labels, loc='upper center', bbox_to_anchor=(0.5,-0.1)) Handles, labels = ax.get_legend_handles_labels() This did in fact resize the figure box as desired. This is apparently similar to calling tight_layout, but instead you allow savefig to consider extra artists in the calculation. #Note that the bbox_extra_artists must be an iterable The code I am looking for is adjusting the savefig call to: fig.savefig('samplefigure', bbox_extra_artists=(lgd,), bbox_inches='tight') Sorry EMS, but I actually just got another response from the matplotlib mailling list (Thanks goes out to Benjamin Root). I have the (only slightly) longer version of this code on pastebin Is there a historical reason? Is Matlab equally poor on this matter? Notice how the final label 'Inverse tan' is actually outside the figure box (and looks badly cutoff - not publication quality!)įinally, I've been told that this is normal behaviour in R and LaTeX, so I'm a little confused why this is so difficult in python. import matplotlib.pyplot as pltĪx.plot(x, np.arctan(x), label='Inverse tan') What I would like to be able to do is dynamically expand the size of the figure box to accommodate the expanding figure legend. The example of a complex legend in the documentation demonstrates the need for this because the legend in their plot actually completely obscures multiple data points. Shrinking the axes, however, is not an ideal solution because it makes the data smaller making it actually more difficult to interpret particularly when its complex and there are lots of things going on. ![]() It seems that the answers in these questions have the luxury of being able to fiddle with the exact shrinking of the axis so that the legend fits. Matplotlib savefig with a legend outside the plot Inverting axes: Flipping the x-/y-axes and inverting an axisĪxis labels: Setting axis labels using dimensions and optionsĪxis ranges: Controlling axes ranges using dimensions, padding and optionsĪxis ticks: Controlling axis tick locations, labels and formattingĪ plot’s title is usually constructed using a formatter which takes the group and label along with the plots dimensions into consideration.I'm familiar with the following questions: Plot hooks: Using custom hooks to modify plotsĪxes: A set of axes provides scales describing the mapping between data and the space on screenĪxis position: Positioning and hiding axes Legends: Controlling the position and styling of the legend Titles: Using title formatting and providing custom titlesīackground: Setting the plot background colorįont sizes: Controlling the font sizes on a plot Plot: Refers to the overall plot which can consist of one or more axes Plots have an overall hierarchy and here we will break down the different components: Specifically this guide provides an overview on controlling the various aspects of a plot including titles, axes, legends and colorbars. While different plotting extensions like bokeh, matplotlib and plotly offer different features and the style options may differ, there are a wide array of options and concepts that are shared across the different extensions. The HoloViews options system allows controlling the various attributes of a plot. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |