[Matplotlib-users] change a matplotlib.lines.Line2D and update the plot

2009-06-15 Thread TP
Hi everybody,

I want to modify a matplotlib.lines.Line2D and update the plot.
I have used Line2D._y member to modify the line. It works. But by doing
canvas.draw() (see example below), the line is not updated on the plot. To
update it, I have to do autoscale_view(). But I do not want the x and y
ranges of the plot to be changed.

How to do this?

Thanks in advance,

Julien

###
from pylab import *
import matplotlib

ion()
f = figure()
s = f.add_subplot("111")

X1 = arange( 0.0, 5.0, 0.1 )
# print X1, X1**2
line = matplotlib.lines.Line2D( X1, X1**2 )


s.add_line( line )

draw()

raw_input("\npress a key to transform y in y+10")
line._y += 10

raw_input("\npress a key to do canvas.draw()")
s.figure.canvas.draw()
draw()
print "The line y has not been updated in y+10"

raw_input("\npress a key to do relim, autoscale and canvas.draw()")
s.relim()
s.autoscale_view()
s.figure.canvas.draw()
draw()
print "The line y has been updated in y+10"
print "But the subplot x and y range has changed"
print "I want the line to be updated without changing x and y ranges"

raw_input("\npress a key to quit")
#

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Grouper use

2009-09-29 Thread TP
Hi everybody,

I try to play with "sharex" feature. Then, I have been guided to the
class "Grouper" of module cbook:

http://matplotlib.sourceforge.net/api/cbook_api.html

So I tried the following example:

##
from matplotlib.cbook import *

g = Grouper()
g.join('a', 'b')
##

I obtain:

Traceback (most recent call last):
  File "test_grouper.py", line 4, in 
g.join('a', 'b')
  File ".../matplotlib/cbook.py", line 1118, in join
set_a = mapping.setdefault(ref(a), [ref(a)])
TypeError: cannot create weak reference to 'str' object

What is the problem?

Thanks in advance,

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Grouper use

2009-09-30 Thread TP
Michael Droettboom wrote:

> Yes -- I'll update the docstring.  The weakref support was added
> afterward during one of my many memory leak crusades ;)
> 
> What were you attempting to do with the Grouper?  You shouldn't have to
> use the class directly to use the sharex/sharey functionality -- it's
> only an implementation detail.

I have not found any way to share an axis after the creation of the
subplot/axis. That is why I use the "join" method of a Grouper after the
subplot/axis has been created. But I would need also a means to "unjoin"
the subplots. Is it possible?

Thanks

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Grouper use

2009-10-01 Thread TP
Michael Droettboom wrote:

> You can use the twinx/twiny methods to join two axes after they've been
> created.
> 
> I don't think we currently provide a way to unjoin the subplots (either
> in the axes or in the Grouper class itself.)  I think that's
> functionality we would need to add.  If you can be so kind as to add a
> feature request to the tracker, it won't get lost.

It is done!
Thanks

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] move a line from one subplot to another

2009-10-05 Thread TP
Hi everybody,

I try to move an instance of matplotlib.lines.Line2D from one subplot to
another. How to do that? I have tried the following code, but the Line2D
does not appear on the second subplot.

Thanks in advance,

Julien

###
from pylab import *

ion()
f = figure()
s = f.add_subplot("211")
line = matplotlib.lines.Line2D([0,1],[0,1],color='m')
s.add_line( line )
s2 = f.add_subplot("212")

draw()

raw_input( 'press a key to remove the line and try to add it to second
subplot' )

line.remove()
s2.add_line( line )
draw()

raw_input('press a key to quit')
#

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] absolute positioning of a subplot in a Figure

2008-09-29 Thread TP
Hi everybody,

Below you will find a small script that plots the graph of a simple function. 
This code is aimed to be embedded in a GUI application.
I set the subplot dimension with the b.set_position([]) command. The floats 
that are given to set_position() are percents relative to the Figure 
dimensions:

[ left corner x, left corner y, width, height ]

So, here I have put [0.1, 0.1, 0.8, 0.8 ] to have a small space between the 
subplot and the Figure border.
But when I resize the figure with the mouse, the space between the subplot and 
the Figure border is growing or decreasing, due to the relative definition of 
the dimensions.
I would like to be able to define subplot size and position in an absolute 
way. For example, I would like to have a space between the left border of the 
figure and the left border of the subplot being constant equal to 10px.

Is this possible?

Thanks a lot

Julien


from pylab import *
import Tkinter as Tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

root = Tk.Tk()
t = arange(0.01, 5.0, 0.01)
s1 = sin(2*pi*t)
f = Figure( figsize = (8,7) )
veryplot = FigureCanvasTkAgg( f
  , master = root )
veryplot.get_tk_widget().pack( side = Tk.LEFT
  , expand = Tk.YES
  , fill = Tk.BOTH )

b = f.add_subplot( 211 )
b.plot( t, s1 )
# [ left corner x, left corner y, width, height ]
b.set_position( [ 0.1, 0.1, 0.8, 0.8 ] )
show()
root.mainloop()


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [EMAIL PROTECTED]

2008-11-07 Thread TP
Michael Droettboom wrote:

> Why are you turning autoscaling off and on?  When you turn it off, the
> autoscale mechanism effectively "ignores" any plots until you turn it
> back on.  If you remove
>
> gca().set_autoscale_on(False)
>
> all seems to work fine.
>
> Is your question that you want to autoscale to a plot after creating it?

I want to be able to "freeze" the plot when adding another curve (because I
want to compare the added curve and a previous one in a small portion of
the X/Y plane, this portion may have been chosen by a zoom of the user
before adding the curve).

Once this comparison has been performed, the user may want to autoscale the
complete plot. If the added curve is larger than the previous one, the
autoscale should take into account the larger curve.

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] plotting a matplotlib.lines.Line2D instance directly

2008-11-29 Thread TP
Hi everybody,

In my own application, I want to specialize matplotlib.lines.Line2D to be
able to deal with units.
Concerning this class, is there a direct means to plot instances?

For example, if I do:

>>> a=matplotlib.lines.Line2D([5,6],[7,8],color='m')

To plot it, I have not found another way than doing:

>>> plot(a.get_xdata(), a.get_ydata())

But it is clumsy, because if I want to keep the line color:

>>> plot(a.get_xdata(), a.get_ydata(), a.get_color())

And so on for marker style, etc.

Is there a direct means to plot a Line2D instance?

Some time ago, a colleague wrote a "Curve_2D" class from scratch, to store a
2D curve, independently from matplotlib. Instead of that, I would like to be
able to specialize Line2D matplotlib class.

Am I compelled to write a .plot() method to Line2D?

In other words, when I do:

>>> a=plot((1,2),(2,3),'r--')

I obtain a Line2D instance:

>>> a[0]


I would like to do the contrary: define a Line2D instance, and then plot
this Line2D. The goal is to avoid re-inventing the wheel in my application,
as did my colleague.

Thanks a lot for your help

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] use of del() to delete a line

2008-12-11 Thread TP
Hi everybody,

I have a question about the behavior of "del()" Python built-in.
In the following example, when I use del() on the copy of a line, it does
not delete it, whereas with the original line, it works. Why? I do not
understand, because the id is the same for the copy and the original:

###
from pylab import *
import Tkinter as Tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
ion()
root = Tk.Tk()
f = Figure( figsize = (8,7) )
veryplot = FigureCanvasTkAgg( f
  , master = root )
veryplot.get_tk_widget().pack( side = Tk.LEFT
  , expand = Tk.YES
  , fill = Tk.BOTH )
b = f.add_subplot( 211 )
t = arange(0.01, 5.0, 0.01)
s1 = sin(2*pi*t)
b.plot( t, s1 )
b.plot( t, s1+1 )
print b.lines
raw_input('press a key to delete a line with a copy')
line_copy = b.lines[-1]
print "original id=", id( b.lines[-1] ), "copy id", id( line_copy )
del( line_copy ) # or b.lines.pop()
b.figure.canvas.draw()
print b.lines
raw_input('press a key to delete a line directly')
print "original id=", id( b.lines[-1] )
del( b.lines[-1] ) # or b.lines.pop()
b.figure.canvas.draw()
print b.lines
raw_input('press a key to quit')
###

Thanks in advance,

Julien


-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] use of del() to delete a line

2008-12-11 Thread TP
TP wrote:

> I have a question about the behavior of "del()" Python built-in.

Ok, del only removes a name from the local namespace.
I have found an old answer of John, below. It seems that a better solution
is to use the remove method of a line instance:

http://osdir.com/ml/python.matplotlib.general/2005-05/msg00045.html

Until now, I used "del" which works well when the complete object hierarchy
is given...

Thanks

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] when the same Line2D is plot on two subplots, it disappears on the two subplots

2008-12-11 Thread TP
Hi,

I use matplotlib 0.91.2.
When I plot the same Line2D on two subplots, it disappears: execute the
following script:

###
from pylab import *
ion()
f = figure()
s = f.add_subplot("211")
curve = matplotlib.lines.Line2D([0,1],[0,1],color='m')
s.add_line( curve )
s2 = f.add_subplot("212")
draw()
raw_input('press a key to delete a line to second subplot')
s2.add_line( curve )
s2.lines[-1].figure.canvas.draw()
print s2.lines[-1].get_visible()
raw_input('press a key to quit')
###

What is the reason for this behavior?

Thanks

Julien

PS: thanks to Friedrich Hagedorn for his correction of my signature.

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1\
+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] strange grid lines when panning

2008-12-15 Thread TP
Hi everybody,

I encounter a strange behavior of TKAgg backend with Matplotlib 0.98.5 and
SVN versions, when panning: the grid lines do not always match the ticks on
the axes:

http://paratribulations.free.fr/help/pan_behavior/strange_lines_when_panning.png

Here is the corresponding script:

http://paratribulations.free.fr/help/pan_behavior/test.py

This problem does not appear with Matplotlib 0.91.2.
Do you reproduce the same strange grid lines with 0.98.5 and SVN version?
Try to pan the curve in all directions, it is rather easy to make this bug
appear.

Just another question: is it normal that on my computer TKAgg has more
antialiasing in 0.98.5 than in 0.91.2? Look at the same plot in 0.91.2
here:

http://paratribulations.free.fr/help/pan_behavior/less_antialiasing_in_0_91_2.png

Thanks

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] strange grid lines when panning

2008-12-15 Thread TP
Michael Droettboom wrote:
  
> This has now been fixed in SVN r6608.
> This has also been fixed in SVN r6609.

Impressive!
Thanks a lot, now it works perfectly!

One hour ago, I discover a bug with cursors (obtained with axvline): the pan
didn't work well with cursors (some cursors remain at the same place). With
your modification, this bug has also disappeared!

Julien

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] updating subplot position with a "position string"

2009-04-11 Thread TP
Hi everybody,

I would like to update a subplot position automatically. Try this example:

##
from pylab import *
f = figure()
s1 = f.add_subplot( '111' )
s1.plot( [5,7], [6,9], 'r' )
s2 = f.add_subplot( '212' )
s2.plot( [5,7], [4,9], 'b' )
show()
##

The problem is that the first subplot does not update its position when 
I add a second subplot with "position string" '212'. I would like the 
first subplot to take the position corresponding to a "position string" 
'211'.

I have not found any means to do this. The figure has some methods 
"subplots_adjust" and "subplotpars", but it seems that I am compelled to 
  set the precise coordinates of the subplots, and so cannot do the 
positioning automatically with a "position string". Am I right? What is 
the best way to deal with this kind of problem?

Thanks a lot

Julien


--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] how to remove a subplot

2009-06-03 Thread TP
Hi everybody,

I want to delete a subplot from my figure. How to do that?

For example, I would like to remove the right subplot in the following
example:


from pylab import *

ion()
f = figure()
s = f.add_subplot("121")
X1 = arange( 0.0, 5.0, 0.1 )
s.plot( X1, X1**2)

s = f.add_subplot("122")
s.plot( X1, sqrt( X1 ))

show()


Thanks in advance,

Julien


-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)


--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] segfault related to NavigationToolbar when using PySide

2012-07-06 Thread TP
Hi everybody,

The following is a small test yielding a segmentation fault with PySide, but 
not with PyQt4.

To test with PyQt4, use:
$ python example.py

To test with PySide:
$ python example.py pyside

With PySide, a segmentation fault appears as soon as the mouse cursor is 
hovering the plot area. Without the NavigationToolbar (try to comment the 
corresponding lines), the problem does not appear. It may be related to the 
display of mouse coordinates in the NavigationToolbar, because when the mouse 
is hovering the NavigationToolbar, no segfault appears.

These are the versions of Qt, PySide, and Matplotlib on my machine:
>>> from PySide import QtCore
>>> QtCore.qVersion()
'4.8.1'
>>> from PySide import __version__
>>> __version__
'1.1.0'
>>> import matplotlib
>>> matplotlib.__version__
'1.1.1rc'

Is this a bug? If yes, does any workaround exist?

Thanks in advance,

TP

### example.py 
#!/usr/bin/env python

import sys

if len(sys.argv) >= 2 and sys.argv[1] == "pyside":
from os import environ
environ['QT_API'] = 'pyside'

from PySide.QtCore import *
from PySide.QtGui import *
else:
from PyQt4.QtCore import *
from PyQt4.QtGui import *


from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as 
FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg

class MplCanvasXY( FigureCanvas ):

def __init__( self, title = None, xlabel = None, ylabel = None, 
parent=None ):

self.fig = Figure()
self.axes = self.fig.add_subplot(111)
self.axes.grid(True)

FigureCanvas.__init__( self, self.fig )
self.setParent( parent )


app = QApplication( sys.argv )
d = QDialog()

vb = QVBoxLayout()
canvas = MplCanvasXY()

vb.addWidget( canvas )
navigationToolbar = NavigationToolbar2QTAgg(
parent = canvas
, canvas = canvas )
vb.addWidget( navigationToolbar )
d.setLayout( vb )

d.show()
sys.exit( app.exec_() )

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] "N" parameter of LinearSegmentedColormap

2012-11-19 Thread TP
Hi everybody,

I have a problem with LinearSegmentedColormap.
In the example below (see PS), I make a colormap, and use it to plot an 
EllipseCollection. My plot is parameterized by a quantity that I have named 
"large_value". For large_value equal to 257, a blue point is obtained at 
(x=0.3, y=0.4). But for large_value equal to 258, it becomes black.

This is because of the way LinearSegmentedColormap is working. It has a 
parameter N which allows to set the "number of colors":

http://matplotlib.org/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap

It is 256 by default, so if I increase N to a greater value, the point remains 
blue for large_value equal to 258.

Now, my real plot (not this dummy example) is such that I need N to be very 
large so as to obtain the right colors on my plot, although very few colors 
are used at the end.
However, when N is too large, the plot becomes very slow, and a lot of memory 
is used; I think because an array is probably built with this size, although 
in theory there is no need to construct such a complete array.

Is there an easy workaround, or have I to study and modify the matplotlib code 
myself?

Thanks,

TP

PS: Here is the test code:
##
from pylab import *
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.collections import CircleCollection

ioff()
large_value = 257 # blue below this value
#large_value = 258 # black above this value
N = 1e5 # 256 by default

cdict = { 'blue': [(0.0, 0.0, 0.0),
(2*1/large_value, 1, 1)
, (1.0, 1.0, 1.0)]
,  'green': [(0.0, 0.0, 0.0),
(2*1/large_value, 0, 0)
, (1.0, 1.0, 1.0)]
, 'red': [(0.0, 0.0, 0.0),
(2*1/large_value, 0, 0),
(1.0, 1.0, 1.0)] }

measures= array([[ 0.2,   0.3,   1],
   [  0.3,   0.4,   2],
   [  0.5,   0.6,   large_value]])

cmap = LinearSegmentedColormap( "cmap foobar"
, cdict
   # , N= N )
)

fig = figure()
axes = fig.add_subplot(111)
ec = CircleCollection( [80]
, offsets = measures[:,:2]
, transOffset = axes.transData
)

ec.set_array( measures[:,2] )
ec.set_cmap( cmap )
axes.add_collection( ec )

show()
##

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] "N" parameter of LinearSegmentedColormap

2012-11-22 Thread TP
On Monday, November 19, 2012 13:53:21 Eric Firing wrote:

> It is not entirely clear to me what you are trying to do, but it sounds
> like increasing N is not the right way to do it. Three things might help
> you find a better way:
> 
> 1) The colormap is intended to work with a norm that handles the
> translation from your data numbers to the 0-1.0 range used to select
> values from the colormap (with exceptions--see below).  You can choose a
> non-default norm, you can write your own, or you can set the parameters
> (vmin, vmax) of the standard linear norm.
> 
> 2) By creating a colormap and calling its set_under, set_over, and
> set_invalid methods, you can control the colors assigned to data values
> that your norm maps respectively to negative numbers, numbers greater
> than 1, and masked values.  See
> http://matplotlib.org/examples/pylab_examples/contourf_demo.html for an
> example of using set_under and set_over.  See
> http://matplotlib.org/examples/pylab_examples/image_masked.html for
> another example, and for an example of controlling the norm parameters
> or using an alternative norm.
> 
> 3) It is also possible to index directly into the colormap if you use a
> norm that returns an integer data type.  An example of such is the
> BoundaryNorm.
> http://matplotlib.org/examples/pylab_examples/multicolored_line.html
> 
> If all you need is a single assignment of a color to a "large value",
> then using the set_over method will take care of it.
> 
> Eric

Thanks for your answer.

My goal is to keep the correct color, i.e. blue, for the point located at 
(x=0.3, y=0.4), even if there are very large values of z on the plot. As I 
said, increasing N is not satisfying because it leads to large amounts of 
memory to be used. But for the time being, this is the only solution I have 
found.

I cannot use the set_over method to do that, because the "large  value" is not 
the only one. Indeed, what I want to do is an imshow plot, with a colorbar 
containing three different linear portions:
* one portion for the values of z contained between the minimum and maximum 
value of z in some measure points.
* one portion for the values of z below the minimum z in the measure points.
* one portion for the values of z above the maximum z in the measure points.

My problem is that I may have very large values on the plot in the range below 
or above the measures z. So I have exactly the problem shown in my dummy 
example of the previous post: all my measures have the same color, although 
they should not, because I have created a colormap that should handle this 
situation (three different linear portions in the map). The only workaround I 
have found is to increase the value of N, but in my case it has to be very 
large, such that the plot is very slow to display, or even can ask for huge 
amounts of memory.

Thus it seems to me that my dummy example given in the previous post covers 
exactly the problem encountered in my real-world imshow function.

Is there a memory-efficient workaround in my dummy example (instead of 
increasing N)?

Thanks,

TP

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] "N" parameter of LinearSegmentedColormap

2012-11-26 Thread TP
On Thursday, November 22, 2012 23:51:08 TP wrote:
> Thus it seems to me that my dummy example given in the previous post covers
> exactly the problem encountered in my real-world imshow function.
> 
> Is there a memory-efficient workaround in my dummy example (instead of
> increasing N)?

I have modified LinearSegmentedColormap so as to solve my problem. The 
difference is that I do not create an huge array in my test case, but instead I 
interpolate linearly in the colormap. This is a quick and dirty code that 
does work in my case, but which does not deal with all cases (no management of 
transparency, no discontinuity in the colormap, etc.)

#
from __future__ import division
from pylab import *
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.collections import CircleCollection

from scipy.interpolate import interp1d


class ContinuousLinearSegmentedColormap( LinearSegmentedColormap ):

def __init__(self, name, segmentdata, gamma=1.0):

LinearSegmentedColormap.__init__( self
, name, segmentdata, gamma = gamma )

def _init(self):

self.N = len( self._segmentdata['red'] )
self._lut = np.ones((self.N, 5), np.float)
for i in range( self.N ):
self._lut[i, 0] = self._segmentdata['red'][i][0]
# 2 because I do not manage discontinuities in color
self._lut[i, 1] = self._segmentdata['red'][i][2]
self._lut[i, 2] = self._segmentdata['green'][i][2]
self._lut[i, 3] = self._segmentdata['blue'][i][2]

self._isinit = True


def __call__(self, X, alpha=None, bytes=False):

if not self._isinit: self._init()
mask_bad = None
if not cbook.iterable(X):
vtype = 'scalar'
xa = np.array([X])
else:
vtype = 'array'
xma = ma.array(X, copy=False)
mask_bad = xma.mask
xa = xma.data.copy()   # Copy here to avoid side effects.
del xma

lut = self._lut.copy()
rgba = np.empty(shape=xa.shape+(4,), dtype=lut.dtype)

# We construct interpolation functions.
fred = interp1d( lut[:,0], lut[:,1])
fgreen = interp1d( lut[:,0], lut[:,2])
fblue = interp1d( lut[:,0], lut[:,3])

rgba[:,3] = 1 # alpha=1 for the time being
for i in range( xa.shape[0] ):
rgba[i,0] = fred( xa[i] )
rgba[i,1] = fgreen( xa[i] )
rgba[i,2] = fblue( xa[i] )

if vtype == 'scalar':
rgba = tuple(rgba[0,:])
return rgba


ioff()


large_value = 257 # blue above this value
large_value = 258 # black above this value
large_value = 1e8

cdict = { 'blue': [(0.0, 0.0, 0.0)
, (2*1/large_value, 1, 1)
, (1.0, 1.0, 1.0)]
,  'green': [(0.0, 0.0, 0.0)
, (2*1/large_value, 0, 0)
, (1.0, 1.0, 1.0)]
, 'red': [(0.0, 0.0, 0.0)
, (2*1/large_value, 0, 0)
, (1.0, 1.0, 1.0)] }

measures= array( [[ 0.2,   0.3,   0],
   [  0.3,   0.4,   2],
   [  0.5,   0.6,   large_value]] )

cmap = ContinuousLinearSegmentedColormap( "cmap foobar"
, cdict
)

fig = figure()
axes = fig.add_subplot(111)
ec = CircleCollection( [80]
, offsets = measures[:,:2]
, transOffset = axes.transData
)

ec.set_array( measures[:,2] )
ec.set_cmap( cmap )
axes.add_collection( ec )

show()
#

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] "N" parameter of LinearSegmentedColormap

2012-11-26 Thread TP
On Monday, November 26, 2012 12:06:40 Eric Firing wrote:
> I'm glad you found a solution, but my sense is that the problem is that
> you are trying to make the colormap do the work of the norm.  The
> colormap is just a set of discrete colors, with a linear mapping to the
> 0-1 scale (apart from the special under, over, and invalid values).  The
> norm is for mapping your data to those colors, however you like, by
> mapping your data to the 0-1 range (again with possible under, over, and
> invalid values).  Did you consider making a custom norm instead of
> modifying the colormap?

Yes, I did.
The problem with the default colormap is that it has not enough colors. I have 
found (I may be wrong) that no norm can change this state of affair. If you are 
able to find a norm to make my example work, i.e. to obtain the middle point in 
blue when large_value is for example 1e10, I am interested.

TP

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] "N" parameter of LinearSegmentedColormap

2012-11-26 Thread TP
On Monday, November 26, 2012 14:10:31 Eric Firing wrote:
> But how many colors can you actually distinguish on the screen, or in a
> plot?  My impression is that the problem is not lack of colors, but
> rather mapping to the color you want. There is no reason that having a
> value in your *data* of 1e10 has to affect how numbers in your data over
> a "normal" range are mapped.
> 
> You are trying to illustrate the problem with an example using 3 colors,
> so how can the number of colors in the colormap be the fundamental
> limitation?

Ok, I understand.
I think that my linear interpolation code has to somewhat be written in a norm 
instead.
At some time, I have looked at examples on Matplotlib website, and at the code 
of pyshared/matplotlib/colors.py, but without having the "flash" to write the 
norm. The next time I will try to write a norm instead (I will put the code 
here of course).

TP



--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users