Hey all,
I've come across quite a problem while using pylab in a recent project.
It seems that the second time I call axvspan or axvline, the view limits
are reset (seemingly arbitrarily). I have attached a code sample
(derived from my project) to demonstrate this issue. The code sample
opens a figure with a single line and vline, adding another set with
every key press. You will see that when the figure is initially plotted,
the view limits are correct for the dataset, however as the second
line/vline is plotted, the limits are stretched. It seems that this must
be a bug in matplotlib. Any help or input anyone could offer would be
greatly appreciated. Thanks,
- Ben
import gtk
from scipy import arange
from matplotlib import pyplot
from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as
FigureCanvas
import random
import math
def get_trace(n_pts):
start_f = 30000.0
end_f = 35000.0
sigma = random.random() * 100.0
center_f = start_f + (end_f-start_f)/2 + random.random() * 200.0
offset = random.random() * 1.0e-5
scale = 1.0e-3
slope = 1.0e-10*random.random()
def gaussian(f):
return offset - scale/(sigma*math.sqrt(2*math.pi)) * math.exp(-(f -
center_f)**2 / (2*sigma**2))
data = []
for f in arange(start_f, end_f, (end_f-start_f)/n_pts):
freq = float(f)
data.append(gaussian(freq) + slope*(freq-start_f))
return data
def add_curve():
fig.clear()
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
data.append(get_trace(n_pts))
for c in data:
ax.plot(freqs, c)
ax.axvline(33000)
ax.legend()
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel("Amplitude (AU)")
canvas.draw()
def key_press_cb(a, b):
print "add curve"
add_curve()
x_lower = 30.0e3
x_upper = 40.0e3
n_pts = 10000
freqs = arange(x_lower, x_upper, (x_upper-x_lower)/n_pts)
win = gtk.Window()
fig = pyplot.figure()
canvas = FigureCanvas(fig)
win.add(canvas)
data = []
add_curve()
win.connect('key-press-event', key_press_cb)
win.show_all()
gtk.main()
-------------------------------------------------------------------------
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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users