Note that there are some explanatory texts on larger screens.

plurals
  1. POmatplotlib: inset axes for multiple boxplots
    primarykey
    data
    text
    <p>I have a few boxplots in matplotlib that I want to zoom in on a particular y-range ([0,0.1]) using <a href="http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html" rel="nofollow noreferrer">inset axes</a>. It is not clear to me from the <a href="http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/examples/inset_locator_demo2.py" rel="nofollow noreferrer">example</a> in the documentation how I should do this for multiple boxplots on the same figure. I was trying to modify the code provided this example, but there was too much unnecessary complexity. My code is pretty simple:</p> <pre><code># dataToPlot is a list of lists, containing some data. plt.figure() plt.boxplot(dataToPlot) plt.savefig( 'image.jpeg', bbox_inches=0) </code></pre> <p>How do I add inset axes and zoom in on the first boxplot of the two? How can I do it for both?</p> <p>EDIT: I tried the code below, but here's what I got: <img src="https://i.stack.imgur.com/ht95r.jpg" alt="enter image description here"></p> <p>What went wrong?</p> <pre><code># what's the meaning of these two parameters? fig = plt.figure(1, [5,4]) # what does 111 mean? ax = fig.add_subplot(111) ax.boxplot(data) # ax.set_xlim(0,21) # done automatically based on the no. of samples, right? # ax.set_ylim(0,300) # done automatically based on max value in my samples, right? # Create the zoomed axes axins = zoomed_inset_axes(ax, 6, loc=1) # zoom = 6, location = 1 (upper right) axins.boxplot(data) # sub region of the original image #here I am selecting the first boxplot by choosing appropriate values for x1 and x2 # on the y-axis, I'm selecting the range which I want to zoom in, right? x1, x2, y1, y2 = 0.9, 1.1, 0.0, 0.01 axins.set_xlim(x1, x2) axins.set_ylim(y1, y2) # even though it's false, I still see all numbers on both axes, how do I remove them? plt.xticks(visible=False) plt.yticks(visible=False) # draw a bbox of the region of the inset axes in the parent axes and # connecting lines between the bbox and the inset axes area # what are fc and ec here? where do loc1 and loc2 come from? mark_inset(ax, axins, loc1=2, loc2=4, fc="none", ec="0.5") plt.savefig( 'img.jpeg', bbox_inches=0) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload