From: Andrea G. <and...@ti...> - 2006-02-04 15:58:20
|
Hello NG, I am having a couple of problems with Matplotlib embedded in wxPython; both are related to the Pylab twinx() function and its corresponding Matplotlib API call. Problem 1: Using the following script: ---------------------------------------------- #!/usr/bin/env python from pylab import * ax1 = subplot(111) t = arange(0.01, 10.0, 0.01) s2 = sin(2*pi*t) plot(t, s2, 'r.') ylabel('sin') # turn off the 2nd axes rectangle with twinx() ax2 = twinx() s1 = exp(t) plot(t, s1, 'b-') xlabel('time (s)') ylabel('exp') show() ---------------------------------------------- Everything works fine but the exponential factor for which the right axis scale is multiplied ("x1e4") is positioned on the left axis, which is clearly misleading. Problem 2: Using the corresponding Matplotlib API calls to use twinx() embedded in wxPython, the same problem as above appears *and* the ylabel for the right axis is positioned on the left axis instead: so I end up with 2 ylabels on the same axis. The script I am running is this one: ---------------------------------------------- #!/usr/bin/env python import wx import matplotlib matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import \ FigureCanvasWxAgg as FigureCanvas from matplotlib.figure import Figure from matplotlib.numerix import arange, sin, exp, pi # wxPython part app = wx.PySimpleApp() frame = wx.Frame(None, -1, "MPL Test", (400, 400)) fig = Figure() canvas = FigureCanvas(frame, -1, fig) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(canvas, 1, wx.LEFT|wx.TOP|wx.GROW) frame.SetSizer(sizer) sizer.Layout() # Plotting part: Left Axis leftaxis = fig.add_subplot(111) leftaxis.yaxis.tick_left() t = arange(0.01, 10.0, 0.01) s2 = sin(2*pi*t) leftaxis.plot(t, s2, 'r.') leftaxis.set_ylabel('sin') # Plotting part: Left Axis rightaxis = fig.add_subplot(111, frameon=False) rightaxis.yaxis.tick_right() s1 = exp(t) rightaxis.plot(t, s1, 'b-') rightaxis.set_xlabel('time (s)') rightaxis.set_ylabel('exp') # wxPython starts frame.CenterOnScreen() frame.Show() app.MainLoop() ---------------------------------------------- If that matters, I am using Matplotlib 0.86.2 on Windows XP/2000, Python 2.4.1, wxPython 2.6.2.1. Thanks in advance for every hint. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77 |