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 7157
import pylab
ax2 = pylab.twinx()
bartonc 6,596
Recognized Expert Expert
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
plot types: line plots, bar charts, log plots, images, pseudocolor
plots, legends, date plots, finance charts and more.
What's new since matplotlib 0.50
This is the first wide release in 5 months and there has been a
tremendous amount of...
|
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.
http://matplotlib.sourceforge.net/matplotlib.pylab.html#-contour
appears to be a good reference if you already know how to use
contour(), but I could glean zero clues from it on how to
actually use contour(). For example, it doesn't explain what
the actual formats/types of the parameters. It...
|
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
so first, i installed python 2.4. that works great! if i type 'python'
in the terminal, it loads python 2.4.
after that, i loaded and installed the matplotlib package from this
|
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) * ((2*math.pi*freq)**2)/10
dati.append(forza)
ax1 = subplot(111)
plot(dati)
|
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 on the matplotlib mailing list, but I have a
hard enough time browsing sourceforge's achives (frequent internal
server errors). Here is some output:
| |
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 on other comps... i used py2exe... i wrote a setup.py whose contents are :
from distutils.core import setup
import py2exe
import matplotlib
setup(console=,
options={
'py2exe': {
'packages' : ,
|
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 I attempt to run the exe created.
In searching the web, it appears this is an issue when others tried to
use py2exe as well. Unfortunately, the few hits I saw doesn't include
enough details to inspire me as to what I should be doing in my
|
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 for this purpose but every time I try to make this exe using a setup file I get these errors. Final.py is my python code.
Traceback (most recent call last):
File "Final.py", line 5, in <module>
File "pylab.pyc", line 1, in <module>
File...
|
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: http://durand.zephyrhosting.net/tremcs/graph_all.png
Would there be any way to fix this? I was thinking of rotating the
text so that there was enough space for each one but the best solution
would be to only display text with the right scale. IE, with a 7 day
graph, each day would...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |