Re: [Matplotlib-users] one data set, two y axis scales

2009-06-06 Thread Sebastian Busch
Jae-Joon Lee wrote:
 ...
 def Tc(Tf): return (5./9.)*(Tf-32)
 
 ax1 = subplot(111) # y-axis in F
 ax2 = twinx() # y-axis in C
 
 def update_ax2(ax1):
 y1, y2 = ax1.get_ylim()
 ax2.set_ylim(Tc(y1), Tc(y2))
 
 # automatically update ylim of ax2 when ylim of ax1 changes.
 ax1.callbacks.connect(ylim_changed, update_ax2)
 ax1.plot([78, 79, 79, 77])
 ...

Thanks, this was also useful for me. I see that you are discussing
shortcomings of twinx -- so perhaps the following is one of those...

I was using this exact script with an additional

ax1.set_yscale('log')
ax2.set_yscale('log')

and the ticks seem to be messed up. I used 'ipython -pylab' with
matplotlib.__version__ '0.98.3'.

Is there something I can do to get the ticks only at the places i would
like them to be?


Thanks,
Sebastian.



signature.asc
Description: OpenPGP digital signature
--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Where to post examples (specifically, one that may be useful for time-evolution plots)

2009-06-06 Thread John Hunter
On Fri, Jun 5, 2009 at 11:39 PM, Tony S Yuton...@mit.edu wrote:
 Are there guidelines for what makes a good example to be included with the
 matplotlib examples?

 I have a matplotlib snippet I'd like to post somewhere, but I'm not sure
 where to put it. I doubt it'd be useful enough to be included with the
 packaged examples. I was thinking about putting it in the matplotlib
 examples in the Scipy cookbook, but I wasn't sure how active the site is.

 In any case, the code I'd like to post changes the color cycle to use
 successive colors from a colormap. I find this really useful for plotting
 curves that evolve in time on the same plot. I've attached an image
 illustrating this idea. The code is pretty simple and is also attached.

I'm happy to post this example in the examples dir, where it will
automatically get picked up in the website gallery and examples dir.
The scipy cookbook is fine too, but I would prefer that a little mini
tutorial be written in rest explaining the example and we can start a
cookbook in the mpl docs.  If you would like to go this route, we can
add a section to the users guide for explained examples, aka a
cookbook.

I am curious though why you prefer to alter the default color cycle
rather than just passing the color in to the plot command -- it seems
more explicit to pass the color in directly rather than rely on the
default cycle.

JDH

--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] x= / y= labels default format is wrong

2009-06-06 Thread Xavier Gnata

 ok. My bad! Sorry.
 I have changed the default to %1.4g so that is matches my usecases *but* I
 agree that correct way to improve it in not that trivial...
 


 You can control the point at which mpl falls over to scientific
 notation.  From the matplotlibrc file (see
 http://matplotlib.sourceforge.net/users/customizing.html)

 axes.formatter.limits : -7, 7 # use scientific notation if log10
# of the axis range is smaller than the
# first or larger than the second

 I'm actually surprised you are seeing problems with images of
 1000x1000 -- it makes me suspect you have an older matplotlib version
 or an older matplotlibrc laying around because at -7,7, which is the
 current default, you should not see exponential formatting until you
 get to much larger sizes.

 JDH
   
I have uncommented the axes.formatter.limits : -7, 7 line  in my 
matplotlibrc.
If have have understood the conclusion of this thread correctly, it 
should be taken info account quite soon, isn't it?

Xavier

--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Where to post examples (specifically, one that may be useful for time-evolution plots)

2009-06-06 Thread Tony S Yu


On Jun 6, 2009, at 9:34 AM, John Hunter wrote:

I'm happy to post this example in the examples dir, where it will
automatically get picked up in the website gallery and examples dir.


That'd be great!


The scipy cookbook is fine too, but I would prefer that a little mini
tutorial be written in rest explaining the example and we can start a
cookbook in the mpl docs.  If you would like to go this route, we can
add a section to the users guide for explained examples, aka a
cookbook.


Now that I think about it, maybe this example isn't suited for a  
cookbook. Or maybe I'm just being lazy and avoiding the work involved  
in writing an explanation. :P



I am curious though why you prefer to alter the default color cycle
rather than just passing the color in to the plot command -- it seems
more explicit to pass the color in directly rather than rely on the
default cycle.
JDH


Actually, I originally cycled through colors in my plot loop, which I  
agree is more explicit. However, I got tired of the extra code  
involved with this method and went looking for a way to change the  
defaults. Plus, I already have of a module of functions I use to  
change matplotlib defaults (different fontsizes, linewidths, etc. for  
publications, presentations, etc), and this function fit quite nicely  
with that module.


-Tony

PS. If it'd be useful to show different ways of cycling through  
colors, here's another version of my example:


#!/usr/bin/env python

This example defines the function ``cycle_cmap``, which changes the default
color cycle to use color intervals from a specified colormap.

The colormap settings are predefined for a few colormaps such that colors go
from light to dark and are restricted from being too light.

These settings are particularly useful for plotting lines that evolve in time,
where there is continuous gradient from light (early times) to dark (late
times).

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

REVERSE_CMAP = ['summer', 'autumn', 'winter', 'spring', 'copper']
CMAP_RANGE = dict(gray={'start':200, 'stop':0},
  Blues={'start':60, 'stop':255},
  Oranges={'start':60, 'stop':255},
  OrRd={'start':60, 'stop':255},
  BuGn={'start':60, 'stop':255},
  PuRd={'start':60, 'stop':255},
  YlGn={'start':60, 'stop':255},
  YlGnBu={'start':60, 'stop':255},
  YlOrBr={'start':60, 'stop':255},
  YlOrRd={'start':60, 'stop':255},
  hot={'start':230, 'stop':0},
  bone={'start':200, 'stop':0},
  pink={'start':160, 'stop':0})
 
def cmap_intervals(cmap='YlOrBr', length=50):
Return evenly spaced intervals of a given colormap `cmap`.

Colormaps listed in REVERSE_CMAP will be cycled in reverse order. Certain 
colormaps have pre-specified color ranges in CMAP_RANGE. These module 
variables ensure that colors cycle from light to dark and light colors are
not too close to white.

cmap - name of a matplotlib colormap (see matplotlib.pyplot.cm)
length - the number of colors used before cycling back to first color. When
`length` is large ( ~10), it is difficult to distinguish between
successive lines because successive colors are very similar.

cm = getattr(plt.cm, cmap)
if cmap in REVERSE_CMAP:
crange = dict(start=255, stop=0)
elif cmap in CMAP_RANGE:
crange = CMAP_RANGE[cmap]
else:
print '%s not in list of preset colormaps; may not be ideal' % cmap
crange = dict(start=0, stop=255)
if length  abs(crange['start'] - crange['stop']):
print ('Warning: the input length is greater than the number of' +
   'colors in the colormap; some colors will be repeated')
idx = np.linspace(crange['start'], crange['stop'], length).astype(np.int)
return cm(idx)

def cycle_cmap(cmap='YlOrBr', length=50):
Set default color cycle of matplotlib to a given colormap `cmap`.

The default color cycle of matplotlib is set to evenly distribute colors in 
color cycle over specified colormap.

Note: this function must be called before *any* plot commands because it
changes the default color cycle.

See ``cmap_intervals`` for input details.

color_cycle = cmap_intervals(cmap, length)
# set_default_color_cycle doesn't play nice with numpy arrays
mpl.axes.set_default_color_cycle(color_cycle.tolist())

if __name__ == '__main__':
numlines = 10
x = np.linspace(0, 10)
phase_shifts = np.linspace(0, np.pi, numlines)

# Change the default color cycle
cycle_cmap(length=numlines)
plt.subplot(311)
for shift in phase_shifts:
plt.plot(x, np.sin(x - shift), linewidth=2)

# Calculate a color cycle from a cmap and pass explicitly to plot
color_cycle = cmap_intervals('summer', 

[Matplotlib-users] Draw a rectangle with a transparent hole

2009-06-06 Thread projetmbc
Hello,
I would like to draw a rectangle and then to cut a disc wich is in the 
rectangle.

Is it possible ?

Christophe


--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] x= / y= labels default format is wrong

2009-06-06 Thread Eric Firing
Xavier Gnata wrote:
 
 ok. My bad! Sorry.
 I have changed the default to %1.4g so that is matches my usecases 
 *but* I
 agree that correct way to improve it in not that trivial...
 


 You can control the point at which mpl falls over to scientific
 notation.  From the matplotlibrc file (see
 http://matplotlib.sourceforge.net/users/customizing.html)

 axes.formatter.limits : -7, 7 # use scientific notation if log10
# of the axis range is smaller than the
# first or larger than the second

 I'm actually surprised you are seeing problems with images of
 1000x1000 -- it makes me suspect you have an older matplotlib version
 or an older matplotlibrc laying around because at -7,7, which is the
 current default, you should not see exponential formatting until you
 get to much larger sizes.

 JDH
   
 I have uncommented the axes.formatter.limits : -7, 7 line  in my 
 matplotlibrc.
 If have have understood the conclusion of this thread correctly, it 
 should be taken info account quite soon, isn't it?

It already *is* taken into account--just not where you want it to be. 
And I don't think it *should* be taken into account there.  It is used 
for the *tick labels*.  I don't think that locking the formatting of 
these to the *cursor readout* is the right thing to do.  The solution to 
your problem involves improving the latter with *no change* to the former.

I have just now committed a small change set that I think you will find 
sufficient improvement for the present, and that I hope no one else will 
find objectionable; but we will have to see how that turns out.  It is 
possible that it will not play well on some backends/dpi/whatever, or 
under some other circumstances.

As noted in the commit message, doing this right requires some changes 
in all the interactive backends.

Eric

 
 Xavier


--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] changing x axis to y and y axis to x in colorbar Object

2009-06-06 Thread feldmaus
Eric Firing efir...@... writes:
 
 I don't understand what your question has to do with the colorbar; but 
 in anything like pcolor, if you swap X and Y, then at the same time you 
 need to transpose Z.

Thanks,

that was my Problem i had to transpose my z. :-)
numpy.transpose(z)

Regards Markus


--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] update colorbar on new incoming data

2009-06-06 Thread feldmaus
Hi All,

The User of my program should use a slider element which lets compute
x,y and z and then my colorbar should also be updated with the new
computed x,y, and z values.

How to do this ?

There is a set_colorbar() method, but i dont know how to use it.
I also found a  set_axes() method.

Here comes a clip of my code:
def drawhistogram(self,min,max):
if not hasattr(self, 'subplot3'):
self.subplot3 = self.figure.add_subplot(111)
self.subplot3.grid(True)
x,y,z = self.computehistogram(self.rastertime)
X,Y = meshgrid(x,y)
self.plots3 = self.subplot3.pcolor(X,Y,np.transpose(z))
self.figure.colorbar(self.plots3)

def repainthistogram(self,rastertime):
x,y,z = self.computehistogram(rastertime)

What for methods to use in my repainthistogram() method ?

regards Markus


--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] update colorbar on new incoming data

2009-06-06 Thread Eric Firing
feldmaus wrote:
 Hi All,
 
 The User of my program should use a slider element which lets compute
 x,y and z and then my colorbar should also be updated with the new
 computed x,y, and z values.
 
 How to do this ?
 
 There is a set_colorbar() method, but i dont know how to use it.
 I also found a  set_axes() method.
 
 Here comes a clip of my code:
 def drawhistogram(self,min,max):
 if not hasattr(self, 'subplot3'):
 self.subplot3 = self.figure.add_subplot(111)
 self.subplot3.grid(True)
 x,y,z = self.computehistogram(self.rastertime)
 X,Y = meshgrid(x,y)
 self.plots3 = self.subplot3.pcolor(X,Y,np.transpose(z))
 self.figure.colorbar(self.plots3)
 
 def repainthistogram(self,rastertime):
 x,y,z = self.computehistogram(rastertime)
 
 What for methods to use in my repainthistogram() method ?

If x,y don't change, and if you are not using masked arrays, then you 
might be able to add something like this:

 self.plots3.set_array(np.transpose(z).ravel())
 self.plots3.autoscale()
 self.figure.canvas.draw()

The colorbar range will be updated automatically.

If x,y do change, then just clear the figure and regenerate it with the 
new data.

Eric

 
 regards Markus
 
 
 --
 OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
 looking to deploy the next generation of Solaris that includes the latest 
 innovations from Sun and the OpenSource community. Download a copy and 
 enjoy capabilities such as Networking, Storage and Virtualization. 
 Go to: http://p.sf.net/sfu/opensolaris-get
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] x= / y= labels default format is wrong

2009-06-06 Thread Xavier Gnata
Eric Firing wrote:
 Xavier Gnata wrote:

 ok. My bad! Sorry.
 I have changed the default to %1.4g so that is matches my usecases 
 *but* I
 agree that correct way to improve it in not that trivial...
 


 You can control the point at which mpl falls over to scientific
 notation.  From the matplotlibrc file (see
 http://matplotlib.sourceforge.net/users/customizing.html)

 axes.formatter.limits : -7, 7 # use scientific notation if log10
# of the axis range is smaller than the
# first or larger than the second

 I'm actually surprised you are seeing problems with images of
 1000x1000 -- it makes me suspect you have an older matplotlib version
 or an older matplotlibrc laying around because at -7,7, which is the
 current default, you should not see exponential formatting until you
 get to much larger sizes.

 JDH
   
 I have uncommented the axes.formatter.limits : -7, 7 line  in my 
 matplotlibrc.
 If have have understood the conclusion of this thread correctly, it 
 should be taken info account quite soon, isn't it?

 It already *is* taken into account--just not where you want it to be. 
 And I don't think it *should* be taken into account there.  It is used 
 for the *tick labels*.  I don't think that locking the formatting of 
 these to the *cursor readout* is the right thing to do.  The solution 
 to your problem involves improving the latter with *no change* to the 
 former.

 I have just now committed a small change set that I think you will 
 find sufficient improvement for the present, and that I hope no one 
 else will find objectionable; but we will have to see how that turns 
 out.  It is possible that it will not play well on some 
 backends/dpi/whatever, or under some other circumstances.

 As noted in the commit message, doing this right requires some changes 
 in all the interactive backends.

 Eric

Ok. Sorry for the conclusion.
Your small change is sufficient for my usecase :).
Thanks. I fully agree with you on the right way to really fix that problem;
I think pylab is great also because I always get feedback on this 
mailing list.


Xavier

--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] update colorbar on new incoming data

2009-06-06 Thread feldmaus
Eric Firing efir...@... writes:

 
 
 If x,y don't change, and if you are not using masked arrays, then you 
 might be able to add something like this:
 
  self.plots3.set_array(np.transpose(z).ravel())
  self.plots3.autoscale()
  self.figure.canvas.draw()
 
 The colorbar range will be updated automatically.
Very very thank you, that worked for me :-)

If i did the help(self.plots3) after defining, 

self.plots3 = self.subplot3.pcolor(X,Y,np.transpose(z))

i had seen this, damned.

again thanks for your answer.

regards Markus


--
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users