 # Make the area a bit larger

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 - old_axes, old_axes - old_axes
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---

Hi,

You can try:

fig, ax = plt.subplots(1,1)
ax.plot(range(10))

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.

···

On Mon, Feb 28, 2011 at 10:48 AM, Andrea Crotti <andrea.crotti.0@…287…> 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 - old_axes, old_axes - old_axes

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@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Gökhan

Gökhan Sever, on 2011-02-28 11:32, 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 - old_axes, old_axes - old_axes
> 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))

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()

best,

···

On Mon, Feb 28, 2011 at 10:48 AM, Andrea Crotti > <andrea.crotti.0@...287...>wrote:

--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7

Gökhan Sever <gokhansever@...287...> writes:

Hi,

You can try:

fig, ax = plt.subplots(1,1)
ax.plot(range(10))

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
Well I can also leave my very convoluted way for now, I'll see later
what to do...

Paul Ivanov <pivanov314@...287...> 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()