I am building a wxPython application that plots some data using matplotlib. I am embedding several axis within a figure by creating several repeatedly calling
ax1 =fig.add_axes([0.1, 0.7, 0.8, 0.2], **axprops)
where axprops is a dict(). This way the plots can share an X-axis. However, I wanted to have one plot have two sets of information. I am familiar with the two_scales.py example, but the same calls do not seem to work in the wx app. Only the original plot succeeds and formats the left axis, while nothing is displayed on the right axis. Is twinx() not supported in wx?
-pJmp
6 7129
import pylab
ax2 = pylab.twinx()
import pylab
ax2 = pylab.twinx()
Thanks, hattawayd, for the very useful information.
I hope you stick around,
Barton
I am trying to accomplish the same thing but with no luck... here is my code: - class CanvasFrame(wx.Panel):
-
-
def __init__(self, parent):
-
wx.Panel.__init__(self, parent, -1)
-
-
self.SetBackgroundColour(wx.NamedColor("WHITE"))
-
-
self.figure = Figure()
-
self.ax1 = self.figure.add_subplot(111)
-
t = arange(0.0,3.0,0.01)
-
s = sin(2*pi*t)
-
-
self.ax1.plot(t,s)
-
self.ax1.set_xlabel('t')
-
self.ax1.set_ylabel('sin(t)')
-
-
self.ax2 = pylab.twinx()
-
s2 = pylab.exp(t)
-
-
self.ax2.plot(t, s2, 'r.')
-
self.ax2.set_ylabel('exp(t)')
-
self.ax2.yaxis.tick_right()
-
-
self.figure_canvas = FigureCanvas(self, -1, self.figure)
-
-
# Note that event is a MplEvent
-
self.figure_canvas.mpl_connect('motion_notify_event', self.UpdateStatusBar)
-
self.figure_canvas.Bind(wx.EVT_ENTER_WINDOW, self.ChangeCursor)
-
-
self.sizer = wx.BoxSizer(wx.VERTICAL)
-
self.sizer.Add(self.figure_canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
-
self.SetSizer(self.sizer)
-
self.Fit()
-
-
self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
-
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
-
self.toolbar.Show()
This is displayed in a wx.Frame however it only displays the first axis (the sin wave one), and nothing for the second. I am assuming that my problem is that I am not associating the second axis with the figure, however with the horrifyingly lackluster matplotlib API/documentation I am at a complete loss of how to do this.
I cannot figure this out and it's just killing me!
I tried using pylab's show() method as in the two_scales example and a window pops up with both y-axes displayed correctly, but then I close that window and my actual application appears with only a single y-axis. Here's my codes.
code: (python) -
class CanvasFrame(wx.Panel):
-
def __init__(self, parent):
-
wx.Panel.__init__(self, parent, -1)
-
-
self.SetBackgroundColour(wx.NamedColor("WHITE"))
-
-
self.time_range = 100.0
-
self.time_div = 0.5
-
self.curr_time = 0.0
-
self.y = [0.0]
-
self.x = [0.0]
-
-
self.tv = track_vars(self)
-
-
self.sizer = wx.BoxSizer(wx.VERTICAL)
-
self.sizer.Add(self.tv.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
-
self.SetSizer(self.sizer)
-
self.Fit()
-
-
self.toolbar = NavigationToolbar2Wx(self.tv.canvas)
-
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
-
self.toolbar.Show()
-
-
class MainWindow(wx.Frame):
-
def __init__(self, *args, **kwargs):
-
wx.Frame.__init__(self, *args, **kwargs)
-
-
icon = wx.Icon(name = 'rDT.ico', type = wx.BITMAP_TYPE_ICO)
-
self.Bind(wx.EVT_CLOSE, self.OnExit)
-
self.SetIcon(icon)
-
self.ds = None
-
-
# Set-up a Status Bar divided into two fields
-
self.sb = self.CreateStatusBar(2)
-
-
# Set up splitter window
-
self.splitwin = SplitterWindow(self)
-
-
# Set up the texual dataviewer for the left pane
-
self.lc = CheckListCtrl(self.splitwin)
-
self.lc.InsertColumn(0, "Variable Name")
-
self.lc.InsertColumn(1, "Value")
-
self.currentItem = 0
-
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.lc)
-
-
# Set up the visual dataviewer for the right pane
-
self.graph = CanvasFrame(self.splitwin)
-
-
# Now we build our menus
-
menu = self.MakeMenu()
-
self.SetMenuBar(menu)
-
-
# Now initialize the split window for program start-up appearance
-
self.splitwin.SetMinimumPaneSize(275)
-
self.splitwin.SplitVertically(self.lc, self.graph, 275)
-
-
# Setup our Heartbeat and Collection timers
-
Global.heartbeat_timer_id = wx.NewId()
-
Global.collection_timer_id = wx.NewId()
-
Global.heartbeat_timer = wx.Timer(self, Global.heartbeat_timer_id)
-
Global.collection_timer = wx.Timer(self, Global.collection_timer_id)
-
wx.EVT_TIMER(self, Global.heartbeat_timer_id, self.OnHeartbeat)
-
wx.EVT_TIMER(self, Global.collection_timer_id, self.OnCollection)
-
-
return None
-
-
class track_vars:
-
def __init__(self, parent):
-
self.figure = Figure()
-
self.ax = self.figure.add_subplot(111)
-
self.ax.set_xlabel('Time')
-
self.ax.set_ylabel('Testing data collection')
-
self.ax2 = pylab.twinx()
-
self.ax2.set_ylabel('Second y-axis')
-
self.ax2.yaxis.tick_right()
-
pylab.show()
-
self.canvas = FigureCanvas(parent, -1, self.figure)
Does anyone have ANY idea why this is not working embedded in a wxPython application?! Anyone? Anyone? Bueller?... Bueller?
Ok, well I figured it out finally... and to any of those poor souls who in the future are trying to accomplish anything similar I basically had to just do it manually (kind of a jerry-rig) and scrap twinx. Here's my code: -
import matplotlib
-
from matplotlib.figure import Figure
-
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
-
...
-
self.figure = Figure()
-
self.ax1 = self.figure.add_subplot(111)
-
self.ax1.set_ylabel('Value')
-
self.ax1.yaxis.tick_left() # w/o this the ticks were echoed on right side
-
self.ax2 = self.figure.add_subplot(111, sharex=self.ax1, frameon=False)
-
self.ax2.set_xlabel('Samples')
-
self.ax2.yaxis.tick_right()
-
self.canvas = FigureCanvas(parent, -1, self.figure)
-
self.canvas.realize()
-
self.canvas.draw()
-
I know, it's very simple and should have been more obvious to me earlier, but oh well. The one thing that I did not bother tackling was figuring out how to place the ylabel on the right side of the graph for ax2, as using ax.set_ylabel placed it right below the label for ax1.
If anyone has any suggestions I'd appreciate them, but I'm not really concerned about putting a label on the right side as it's rather redundant anyway.
The one thing that I did not bother tackling was figuring out how to place the ylabel on the right side of the graph for ax2, as using ax.set_ylabel placed it right below the label for ax1.
Does anyone have a solution to the problem of the position of the second ylabel? My data is such that I really need two different labels, but all my attempts have failed so far.
Thanks!
Greetings,
Jougs!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Hunter |
last post by:
matplotlib is a 2D plotting library for python. You can use
matplotlib interactively from a python shell or IDE, or embed it in
GUI applications (WX, GTK, and Tkinter). matplotlib supports many...
|
by: Grant Edwards |
last post by:
I downloaded examples/contour_demo.py, and it doesn't run.
I've searched both the user guide and the Wiki for "contour"
and got zero hits.
...
|
by: spross |
last post by:
hi all
i have to use matplotlib on mac os x. on the official site of
matplotlib, i found a link to precompiled python packages for mac os x:
http://pythonmac.org/packages/py24-fat/index.html
...
|
by: luca72 |
last post by:
Hello at all.
I need to do a real time plot where on the frame i have this like limit
line:
import math
dati =
for freq in range(int(freqiniziale), (int(freqfinale )+ 1)):
forza = float(massa)...
|
by: Bill Jackson |
last post by:
Hi, I'm having some trouble plotting with the following matplotlibrc:
text.usetex : True
I tried clearing the cache files under ~/.matplotlib, but this did not
help the problem. I'd post...
|
by: vajratkarviraj |
last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution...
|
by: John Henry |
last post by:
Has anybody been able to create an exe of their python applications
involving matplotlib using pyinstall (ver 1.3)? I am getting a:
RuntimeError: Could not find the matplotlib data files
when...
|
by: PamMish1982 |
last post by:
Hi all,
I have recently started using Python and I am trying to make a GUI out of Tkinter. I am using matplotlib for the graphic purposes. I have to make a exe file from this code. I use py2exe...
|
by: Durand |
last post by:
I got a really annoying problem with datetime graphs. The problem is
that with a long range time graph, the text on the x axis keeps
overlapping like here:...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |