## Re: [Matplotlib-users] Make the area a bit larger

 Re: [Matplotlib-users] Make the area a bit larger From: Andrea Crotti - 2011-03-01 11:59:06 ```Paul Ivanov writes: > > Hi Andrea, > > I think Gökhan is pointing out a different feature than the one > you want. You seem to want to adjust the x and y limits of the > plot to be some fraction larger than the data that's plotted. > > You can do this with: > > ax = plt.subplot(111) > ax.plot(range(10)) > ax.set_ymargin(.2) > ax.set_xmargin(.1) > # or ax.margins(.1,.2) > ax.autoscale() > plt.draw() > > see also the docstring for ax.autoscale_view for more. > > best, Uhm also autoscale and set_xmargin are not implemented in my version of matplotlib, too bad I'll just keep my hack for now... ```

 [Matplotlib-users] Make the area a bit larger From: Andrea Crotti - 2011-02-28 18:18:51 ```So since I wanted some space on the borders of my graph, I did this really extremely convoluted thing, which apparently works... I get a 10% more area on each side, but I'm quite sure there's a better way to this, right? I didn't find any function to pass an increment to the size that's why I did this mess... --8<---------------cut here---------------start------------->8--- old_axes = plt.axis() sizes = old_axes[1] - old_axes[0], old_axes[3] - old_axes[2] offset = lambda x: int((float(x) / 10)) new_axes = [] for i in range(len(old_axes)): new_val = old_axes[i] + (((-1) ** (i + 1)) * offset(sizes[i % 2])) new_axes.append(new_val) plt.axis(new_axes) --8<---------------cut here---------------end--------------->8--- ```
 Re: [Matplotlib-users] Make the area a bit larger From: Gökhan Sever - 2011-02-28 18:32:56 Attachments: Message as HTML ```On Mon, Feb 28, 2011 at 10:48 AM, Andrea Crotti wrote: > So since I wanted some space on the borders of my graph, I did this > really extremely convoluted thing, which apparently works... > I get a 10% more area on each side, but I'm quite sure there's a better > way to this, right? > > I didn't find any function to pass an increment to the size that's why I > did this mess... > > --8<---------------cut here---------------start------------->8--- > old_axes = plt.axis() > sizes = old_axes[1] - old_axes[0], old_axes[3] - old_axes[2] > offset = lambda x: int((float(x) / 10)) > new_axes = [] > > for i in range(len(old_axes)): > new_val = old_axes[i] + (((-1) ** (i + 1)) * offset(sizes[i % > 2])) > new_axes.append(new_val) > > plt.axis(new_axes) > --8<---------------cut here---------------end--------------->8--- > > > > ------------------------------------------------------------------------------ > Free Software Download: Index, Search & Analyze Logs and other IT data in > Real-Time with Splunk. Collect, index and harness all the fast moving IT > data > generated by your applications, servers and devices whether physical, > virtual > or in the cloud. Deliver compliance at lower cost and gain new business > insights. http://p.sf.net/sfu/splunk-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > Hi, You can try: fig, ax = plt.subplots(1,1) ax.plot(range(10)) fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) If you choose WXAgg as your backend you get a nice config tool to adjust spacing in the figure. Then just pass those numbers into .subplots_adjust method once you are satisfied. -- Gökhan ```
 Re: [Matplotlib-users] Make the area a bit larger From: Paul Ivanov - 2011-02-28 19:30:22 Attachments: application/pgp-signature ```Gökhan Sever, on 2011-02-28 11:32, wrote: > On Mon, Feb 28, 2011 at 10:48 AM, Andrea Crotti > wrote: > > > So since I wanted some space on the borders of my graph, I did this > > really extremely convoluted thing, which apparently works... > > I get a 10% more area on each side, but I'm quite sure there's a better > > way to this, right? > > > > I didn't find any function to pass an increment to the size that's why I > > did this mess... > > > > --8<---------------cut here---------------start------------->8--- > > old_axes = plt.axis() > > sizes = old_axes[1] - old_axes[0], old_axes[3] - old_axes[2] > > offset = lambda x: int((float(x) / 10)) > > new_axes = [] > > > > for i in range(len(old_axes)): > > new_val = old_axes[i] + (((-1) ** (i + 1)) * offset(sizes[i % > > 2])) > > new_axes.append(new_val) > > > > plt.axis(new_axes) > > --8<---------------cut here---------------end--------------->8--- > > You can try: > > fig, ax = plt.subplots(1,1) > ax.plot(range(10)) > fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) Hi Andrea, I think Gökhan is pointing out a different feature than the one you want. You seem to want to adjust the x and y limits of the plot to be some fraction larger than the data that's plotted. You can do this with: ax = plt.subplot(111) ax.plot(range(10)) ax.set_ymargin(.2) ax.set_xmargin(.1) # or ax.margins(.1,.2) ax.autoscale() plt.draw() see also the docstring for ax.autoscale_view for more. best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 ```
 Re: [Matplotlib-users] Make the area a bit larger From: Andrea Crotti - 2011-03-01 09:29:42 ```Gökhan Sever writes: > Hi, > > You can try: > > fig, ax = plt.subplots(1,1) > ax.plot(range(10)) > fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) > > If you choose WXAgg as your backend you get a nice config tool to adjust > spacing in the figure. Then just pass those numbers into .subplots_adjust > method once you are satisfied. Uhm strange, with the version of matplotlib that I have know I have subplots_adjust, but I don't have plt.subplots, was it added later? Well I can also leave my very convoluted way for now, I'll see later what to do... ```
 Re: [Matplotlib-users] Make the area a bit larger From: Andrea Crotti - 2011-03-01 11:59:06 ```Paul Ivanov writes: > > Hi Andrea, > > I think Gökhan is pointing out a different feature than the one > you want. You seem to want to adjust the x and y limits of the > plot to be some fraction larger than the data that's plotted. > > You can do this with: > > ax = plt.subplot(111) > ax.plot(range(10)) > ax.set_ymargin(.2) > ax.set_xmargin(.1) > # or ax.margins(.1,.2) > ax.autoscale() > plt.draw() > > see also the docstring for ax.autoscale_view for more. > > best, Uhm also autoscale and set_xmargin are not implemented in my version of matplotlib, too bad I'll just keep my hack for now... ```
 Re: [Matplotlib-users] Make the area a bit larger From: Paul Ivanov - 2011-03-01 21:48:18 Attachments: application/pgp-signature ```Andrea Crotti, on 2011-03-01 10:29, wrote: > Gökhan Sever writes: > > You can try: > > > > fig, ax = plt.subplots(1,1) > > ax.plot(range(10)) > > fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95) > > > > Uhm strange, with the version of matplotlib that I have know I have > subplots_adjust, but I don't have plt.subplots, was it added later? > Well I can also leave my very convoluted way for now, I'll see later > what to do... plt.subplots was added somewhat recently - in this instance it's equivalent to : fig = plt.figure() ax = plt.subplot(1,1,1) Andrea Crotti, on 2011-03-01 12:58, wrote: > Paul Ivanov writes: > > You can do this with: > > > > ax = plt.subplot(111) > > ax.plot(range(10)) > > ax.set_ymargin(.2) > > ax.set_xmargin(.1) > > # or ax.margins(.1,.2) > > ax.autoscale() > > plt.draw() > > > > see also the docstring for ax.autoscale_view for more. > > Uhm also autoscale and set_xmargin are not implemented in my version of > matplotlib, too bad I'll just keep my hack for now... Ok, these were added within the past year as well. I think you should have an older version of ax.autoscale_view which does something similar - but it's effectively what you have done in your original example (though I'm not sure why you want cast everything as an int there, perhaps that's just what makes sense for the data you have). you can see the current code here, if you're curious: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes.py#L1774 best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 ```