SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Andrea C. <and...@gm...> - 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---
From: Gökhan S. <gok...@gm...> - 2011年02月28日 18:32:56
On Mon, Feb 28, 2011 at 10:48 AM, Andrea Crotti
<and...@gm...>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
> Mat...@li...
> 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
From: Paul I. <piv...@gm...> - 2011年02月28日 19:30:22
Gökhan Sever, on 2011年02月28日 11:32, wrote:
> On Mon, Feb 28, 2011 at 10:48 AM, Andrea Crotti
> <and...@gm...>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 
From: Andrea C. <and...@gm...> - 2011年03月01日 09:29:42
Gökhan Sever <gok...@gm...> 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...
From: Andrea C. <and...@gm...> - 2011年03月01日 11:59:06
Paul Ivanov <piv...@gm...> 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...
From: Paul I. <piv...@gm...> - 2011年03月01日 21:48:18
Andrea Crotti, on 2011年03月01日 10:29, wrote:
> Gökhan Sever <gok...@gm...> 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 <piv...@gm...> 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 
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /