change a matplotlib.lines.Line2D and update the plot

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)

Turn autoscaling off with

  ax.set_autoscale_on(False)

update the line with

  line.set_ydata(newdata)

draw the canvas with

  fig.canvas.draw()

JDH

···

On Mon, Jun 15, 2009 at 9:36 AM, TP<paratribulations@...185...> wrote:

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.

I think you want the 'line.set_ydata' method, where you pass the new Y
data for your plot (there are also set_xdata and set_data to set,
respectively, the X data and the whole set of X/Y); then call a draw
on the canvas.

Regards,

···

On Mon, Jun 15, 2009 at 16:36, TP<paratribulations@...185...> wrote:

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.

--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi