[Matplotlib-users] axisGrid - blank subplots

2011-02-28 Thread Boyle, Jim
I am using AxesGrid (from mpl_toolkits.axes_grid1 import AxesGrid) to generate 
multi-panel plots.
It does very well except I have a problem with a blank subplot.
I have 5 plots to display and the geometry of nrows_ncols=(3,2) produces the 
plot that I want 
except there is a frame placed in the last position - for which I did not call 
a plot.

I cannot figure out an elegant way to supress this frame. The kludge I use now 
is to just set the
edgecolor of the last grid subplot to the background and so it is not visible.

All the examples  have an even number of subplot figures so the grid is filled 
and this situation does not occur.

--Jim


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


[Matplotlib-users] Make the area a bit larger

2011-02-28 Thread Andrea Crotti
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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


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

2011-02-28 Thread Gökhan Sever
On Mon, Feb 28, 2011 at 10:48 AM, Andrea Crotti
andrea.crott...@gmail.comwrote:

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


Re: [Matplotlib-users] Best way to modify plot / subplot

2011-02-28 Thread Benjamin Root
On Sun, Feb 27, 2011 at 4:49 PM, David Andrews irbda...@gmail.com wrote:

 Hi All,

 I'm looking for some suggestions about two problems:

 1) I'm converting some figure generating code from IDL into
 Python/matplotlib.  Image attached showing this figure.
 IDL being a functional programming language for the most part,
 creating wrappers around various subroutines is trivial and generally
 the simplest way to modify their behavior.
 For example, in dealing with phase data (which can take values between
 0º and 360º, and are 'wrapped' around this interval, such that 270º +
 180º = 90º and so on), I have some stuff in IDL that instead over
 simply 'overplotting' some (x,y) data, it will do a quick loop and
 instead overplot (x, y + n * 360º) for n = -1, ..., 1 (or some other
 number of repetitions, you get the idea).

 Now, in matplotlib, while I can do this pretty easily, I suspect there
 are better ways?  I suppose I could write a subclass of
 matplotlib.axes.Axes for example, that does the 360º repetition itself
 across not just the plot() method but for others also?  But
 implementing a whole new class for this may be complicated, and I am
 sort of lost as to how I would then get that working with the pylab
 stateful interface?

 I'm reasonably new to OO programming, and I'm still getting my head
 round the 'best' way to do things like this.

 Alternatively, having a class that describes individual data points, I
 could define a plot() method for them?

 class MyData():
...
plot(self, axes):
...
axes.plot(self.x, self.y + n * 360)

 But then, that seems to 'break' some rules, as I don't see much
 matplotlib code in which you do 'data.plot()' as opposed to
 'axes.plot()' - the order seems wrong?

 2) Somewhat similar to the first question.  The figure includes (at
 the top) some ancillary data (showing lengths of orbit and year
 numbers).  In IDL its done simply by filling polygons in normal / page
 coordinates - but again, I think it could be better done using OO
 somehow?  Effectively, that top row could be thought of as a separate
 subplot.  What would be the efficient / sensible / pythonic way to go
 about reproducing this. Another subclass of Axes?

 Many thanks,

 Dave


Dave,

Generally speaking, if your first thought is Should I subclass the Axes
class? then you might need to take a second look at what matplotlib has to
offer out of the box.  Granted, the graph you wish to duplicate is very
complex, but let us break it down into various components.

First, you want multiple subplots to appear vertically stacked and share
the same x-axis.  Here is an example of how to do that:

http://matplotlib.sourceforge.net/examples/pylab_examples/ganged_plots.html

(Note that I personally advocate against the from pylab import * code
style, and this example could easily be redone from the pyplot interface
instead.)

Here is another example where the person used LineCollections with defined
offsets.  This has the advantage of using a single axes object, but might be
difficult to handle the y-axis.

http://matplotlib.sourceforge.net/examples/pylab_examples/mri_with_eeg.html


To have multiple x-axis tick labels for a common y-axis is a concept called
twiny.  The following is an example of doing twinx (multiple y-axis tick
labels for a common x-axis), but the concept is the same:

http://matplotlib.sourceforge.net/examples/api/two_scales.html

This is another example showing a different way of doing that:

http://matplotlib.sourceforge.net/examples/axes_grid/simple_axisline4.html

As for some of the markings around the graph, I am not entirely certain how
to implement that.  I will leave that for others to suggest ideas for.

I hope this is helpful!
Ben Root
--
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


Re: [Matplotlib-users] axisGrid - blank subplots

2011-02-28 Thread Paul Ivanov
Boyle, Jim, on 2011-02-28 08:40,  wrote:
 I am using AxesGrid (from mpl_toolkits.axes_grid1 import
 AxesGrid) to generate multi-panel plots.  It does very well
 except I have a problem with a blank subplot.  I have 5 plots
 to display and the geometry of nrows_ncols=(3,2) produces the
 plot that I want except there is a frame placed in the last
 position - for which I did not call a plot.
 
 I cannot figure out an elegant way to supress this frame. The
 kludge I use now is to just set the edgecolor of the last grid
 subplot to the background and so it is not visible.
 
 All the examples  have an even number of subplot figures so the
 grid is filled and this situation does not occur.

Hi Jim,

how's this:

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid
ag = AxesGrid(plt.figure(),(0,0,1,1),(2,3))
ag.axes_all[-1].set_visible(False)

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


signature.asc
Description: Digital signature
--
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


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

2011-02-28 Thread Paul Ivanov
Gökhan Sever, on 2011-02-28 11:32,  wrote:
 On Mon, Feb 28, 2011 at 10:48 AM, Andrea Crotti
 andrea.crott...@gmail.comwrote:
 
  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 


signature.asc
Description: Digital signature
--
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


Re: [Matplotlib-users] Best way to modify plot / subplot

2011-02-28 Thread Goyo
David, the preferred way to custom plots seems to be passing an Axes
instance to the plotting function. Some tricks allow use of
pylab/pyplot style:

def custom_plot(x, y, axes=None):
...
if axes is None: axes = pyplot.gca()
axes.plot(x, y)


What you don't get this way is the axes.custom_plot(x, y) sintax,
which requires subclassing Axes. But doing this is not common and not
straighforward if you want it to work well with pyplot.subplot() and
the like.

Maybe monkey patching would work but well, you know... I never tried it anyway.

Goyo

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


[Matplotlib-users] Issue with imshow and usetex

2011-02-28 Thread Thomas Robitaille
Hi,

In the following example:

---

import numpy as np

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.imshow(np.random.random((1024, 1024)), interpolation='nearest')
fig.savefig('test_1.eps')

mpl.rc('text', usetex=True)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.imshow(np.random.random((1024, 1024)), interpolation='nearest')
fig.savefig('test_2.eps')

---

the file test_2.eps is almost 6 times larger than test_1.eps, and takes much 
longer to draw. It looks like in the first case, the image is rendered as a 
bitmap (the way it should be), whereas in the second case each pixel is drawn 
individually as a polygon. Is this a bug?

I am using r8988 of matplotlib.

Thanks for any help!

Thomas
--
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


Re: [Matplotlib-users] axisGrid - blank subplots

2011-02-28 Thread Jae-Joon Lee
You may use ngrids keyword parameter.
i.e.,., nrows_ncols=(3,2), ngrids=5

Regards,

-JJ



On Tue, Mar 1, 2011 at 1:40 AM, Boyle, Jim boy...@llnl.gov wrote:
 I am using AxesGrid (from mpl_toolkits.axes_grid1 import AxesGrid) to 
 generate multi-panel plots.
 It does very well except I have a problem with a blank subplot.
 I have 5 plots to display and the geometry of nrows_ncols=(3,2) produces the 
 plot that I want
 except there is a frame placed in the last position - for which I did not 
 call a plot.

 I cannot figure out an elegant way to supress this frame. The kludge I use 
 now is to just set the
 edgecolor of the last grid subplot to the background and so it is not visible.

 All the examples  have an even number of subplot figures so the grid is 
 filled and this situation does not occur.

 --Jim


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


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


Re: [Matplotlib-users] savefig bbox_inches='tight' does not consider suptitle

2011-02-28 Thread Jae-Joon Lee
On Fri, Feb 25, 2011 at 9:15 PM, Yuri D'Elia wav...@users.sf.net wrote:
 In the following:

 
 import matplotlib as mpl
 import matplotlib.figure
 import matplotlib.backends.backend_agg

 fig = mpl.figure.Figure()
 cvs = mpl.backends.backend_agg.FigureCanvasAgg(fig)
 fig.set_size_inches((20,20))
 fig.suptitle(Horray!, fontsize=20)
 plot = fig.add_subplot(111)
 plot.set_title(Subtitle)
 plot.plot([1,2,3], [3,2,1])
 fig.savefig(out.png, bbox_inches='tight')


 suptitle is stripped from the figure.
 Of course the title is present if you unset bbox_inches, but that's 
 unexpected behavior for me.

 Is this a bug?

Unfortunately, bbox_inches option is never meant to be complete in
figuring out the exact  size of the figure area.
However, you  can use bbox_extra_artists keyword argument to specify
additional artists that should be considered when dertermining the
plot size.

mytitle = fig.suptitle(Horray!, fontsize=20)

...

fig.savefig(out.png, bbox_inches='tight', bbox_extra_artists=[mytitle])

Regards,

-JJ




 Thanks


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


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