Hello,
It's my first post on this forum and I'm very happy to discover a forum
dedicated to matplotlib. I 've begun recently a development with matplotlib
inside my python (2.7)application.
In a first step I've developped a stand alone graphical display and it runs
properly. In a second step, I try to manage this graphical display through gtk
(because my main application is in python/gtk) : now, most of functionalities
run well, but labels on my 3 axes are no more displayed and I don't understand
why.
Thank you for all suggestions.
Here is the source code with gtk
-----------------------------------------------------------------------------------------------------------------
import sys
import gtk
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as
NavigationToolbar
from StringIO import StringIO # StringIO behaves like a file object
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import colorConverter
from matplotlib.widgets import Button
class SectorDisplay2__:
"""
Display view of sectors and volumes
"""
def __init__(self):
win = gtk.Window()
win.connect("destroy",self.SectorDisplayClosePanel)
win.set_default_size(800,800)
vbox = gtk.VBox()
win.add(vbox)
fig = Figure()
canvas = FigureCanvas(fig) # a gtk.DrawingArea
ax = Axes3D(fig)
#get lines as csv description
line = ""
line =
line+"VOL1;P4120;0;999;-49.68722222222222;-1.52166666666667;\n"
line =
line+"VOL1;P4121;0;999;-49.68722222222222;-2.20722222222222;\n"
line =
line+"VOL1;P1421;0;999;-49.23750000000000;-2.20722222222222;\n"
line =
line+"VOL1;P1422;0;999;-49.23750000000000;-1.52166666666667;\n"
line =
line+"VOL1;P4120;0;999;-49.68722222222222;-1.52166666666667;\n"
lines = StringIO(line)
# get the list of point coordinates and level
data = np.loadtxt(lines,
delimiter=';',
usecols = (0,1,2,3,4,5), # 0=volume 1=point
2=lower level 3=upper_level, 4=lat 5=long
dtype =
np.dtype({'names':['volume','point','lower','upper','lat','long'],
'formats':
['S20','S5','i4','i4','f4','f4']}) )
# Get one particular volume
onevolume = data[data['volume']=="VOL1"]
ax.plot(onevolume['long'],onevolume['lat'],onevolume['upper'])
ax.plot(onevolume['long'],onevolume['lat'],onevolume['lower'])
for i in range(len(onevolume)-1):
ax.plot([onevolume['long'][i],onevolume['long'][i]],
[onevolume['lat'][i],onevolume['lat'][i]],
[onevolume['lower'][i],onevolume['upper'][i]])
ax.set_ylabel('Latitude (deg)')
ax.set_xlabel('Longitude (deg)')
ax.set_zlabel('Level (100xfeet)')
ax.set_title('Volumic definition')
vbox.pack_start(canvas)
toolbar = NavigationToolbar(canvas,win)
vbox.pack_start(toolbar,False,False)
win.show_all()
# Run the Gtk mainloop
gtk.main()
def SectorDisplayClosePanel(self,caller):
gtk.main_quit()
if __name__ == '__main__':
SectorDisplay2__()
-------------------------------------------------------------------------------------
Here is the initial source code without gtk:
-------------------------------------------------------------------------------------
import sys
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as
NavigationToolbar
from StringIO import StringIO # StringIO behaves like a file object
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import colorConverter
from matplotlib.widgets import Button
class SectorDisplay2__:
"""
Display view of sectors and volumes
"""
def __init__(self):
"""
@param parentWin: Window which is parent of this window
@type parentWin: Widget
@param typevol: give the type of volume : volume, sector, non
controlled area ...
@type typevol: str
@param entity_name: entity to display
@type entity_name: str
@type application: <Application__>
@param application: instance of class Application__
@param class_creation: indicates a class creation and not only
a call to Class__.__init__
@type class_creation: boolean
"""
fig = plt.figure()
ax = Axes3D(fig)
#get lines as csv description
line = ""
line =
line+"VOL1;P4120;0;999;-49.68722222222222;-1.52166666666667;\n"
line =
line+"VOL1;P4121;0;999;-49.68722222222222;-2.20722222222222;\n"
line =
line+"VOL1;P1421;0;999;-49.23750000000000;-2.20722222222222;\n"
line =
line+"VOL1;P1422;0;999;-49.23750000000000;-1.52166666666667;\n"
line =
line+"VOL1;P4120;0;999;-49.68722222222222;-1.52166666666667;\n"
lines = StringIO(line)
# get the list of point coordinates and level
data = np.loadtxt(lines,
delimiter=';',
usecols = (0,1,2,3,4,5), # 0=volume 1=point
2=lower level 3=upper_level, 4=lat 5=long
dtype =
np.dtype({'names':['volume','point','lower','upper','lat','long'],
'formats':
['S20','S5','i4','i4','f4','f4']}) )
# Get one particular volume
onevolume = data[data['volume']=="VOL1"]
ax.plot(onevolume['long'],onevolume['lat'],onevolume['upper'])
ax.plot(onevolume['long'],onevolume['lat'],onevolume['lower'])
for i in range(len(onevolume)-1):
ax.plot([onevolume['long'][i],onevolume['long'][i]],
[onevolume['lat'][i],onevolume['lat'][i]],
[onevolume['lower'][i],onevolume['upper'][i]])
ax.set_ylabel('Latitude (deg)')
ax.set_xlabel('Longitude (deg)')
ax.set_zlabel('Level (100xfeet)')
ax.set_title('Volumic definition')
plt.show()
def SectorDisplayClosePanel(self,caller):
plt.close()
if __name__ == '__main__':
SectorDisplay2__()
-------------------------------------------------------------------------------------
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users