本文整理汇总了Python中matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg.show方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasGTK3Agg.show方法的具体用法?Python FigureCanvasGTK3Agg.show怎么用?Python FigureCanvasGTK3Agg.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg
的用法示例。
在下文中一共展示了FigureCanvasGTK3Agg.show方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawZones
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
def drawZones(self,shape,xvalues,yvalues,xlabel,ylabel,title,color,zones=None):
logging.debug('>>')
logging.debug("Type: pie | title: %s | col: %s | xlabel: %s | ylabel: %s",
title, color, xlabel, ylabel)
self.removeVboxChildren()
figure = Figure()
logging.debug("Figure: %s", figure)
axis = figure.add_subplot(111)
labels = [_("rest")]
colors = ["#ffffff"]
for zone in reversed(zones):
labels.append(zone[3])
colors.append(zone[2])
zone_sum = [0]*6
for value in yvalues[0]:
# bisection, it's faster
if value <= zones[2][1]:
if value <= zones[4][1]:
if value <= zones[4][0]:
zone_sum[0] += 1
else:
zone_sum[1] += 1
else:
if value <= zones[3][1]:
zone_sum[2] += 1
else:
zone_sum[3] += 1
else:
if value <= zones[1][1]:
zone_sum[4] += 1
else:
zone_sum[5] += 1
if shape == "pie":
self._piePlot(axis, zone_sum, colors, labels)
elif shape == "histogram":
self._barPlot(axis, zone_sum, colors, labels)
canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea
canvas.show()
for child in self.vbox.get_children():
logging.debug('Child available: %s', child)
self.vbox.pack_start(canvas, True, True, 0)
logging.debug('<<')
示例2: plotOffHours
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
def plotOffHours(self):
'''
Returns a FigureCanvasGTK3Agg object that displays a graphical representation
of self._offHours
'''
(t, val) = self.orderDict(self._offHours)
t = np.array(t)
val = np.array(val)
val = val/self._STD_DAY
#plt.xkcd(scale=1, length=100, randomness=2)
f = plt.figure(figsize=(6,4), dpi=100)
a = f.add_subplot(111)
z = np.zeros(len(t))
a.fill_between(t, z, val, val > 0.0, color='green', alpha=.25, interpolate=True)
a.fill_between(t, z, val, val < 0.0, color='red', alpha=.25, interpolate=True)
a.grid(True)
f.autofmt_xdate()
# Generate X ticks
xticks = list()
xtick_labels = list()
xticks.append(t[0])
xtick_labels.append(dt.strftime(t[0], "%b %y").decode("utf-8")) # avoids problems with the accentuated months
curr_month = t[0].month
for d in t:
if d.month != curr_month :
curr_month = d.month
xticks.append(dt(day=1,month=curr_month, year=d.year))
xtick_labels.append(dt.strftime(d, "%b %y").decode("utf-8"))
a.set_xticks(xticks)
a.set_xticklabels(xtick_labels, fontsize=8)
# Generate Y ticks
yticks = np.arange(min(val), max(val), 2.5)
a.set_yticks(yticks)
canvas = FigureCanvas(f) # a gtk.DrawingArea
canvas.show()
return canvas
示例3: rate
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
a2.set_ylim(-10, 80)
a3.set_ylim(-10, 80)
a2.set_ylabel('Flow rate (Q lit/min)')
a3.set_ylabel('Eng Values')
a.set_ylabel('Pump Out: P (bar) and Q (lit/min)')
scrolledwindow1.set_border_width(5)
samples_no = 1
canvas = FigureCanvas(f) # a Gtk.DrawingArea
canvas.set_size_request(800, 450)
scrolledwindow1.add_with_viewport(canvas)
canvas.show()
if len(cfgItems) > 0:
samples_no = smtConfig.getint('General', 'samples_no')
if smtConfig.has_option('Output', 'folder'):
output_folder = smtConfig.get('Output', 'folder')
if smtConfig.has_option('Manifold_1', 'host') and smtConfig.has_option('Manifold_1', 'port'):
manifold_host_1 = smtConfig.get('Manifold_1', 'host')
manifold_port_1 = smtConfig.get('Manifold_1', 'port')
a_low= smtConfig.getint('Manifold_1', 'low')
a_high=smtConfig.getint('Manifold_1', 'high')
p_low=smtConfig.getint('Manifold_1', 'p_low')
p_high=smtConfig.getint('Manifold_1', 'p_high')
q_low=smtConfig.getint('Manifold_1', 'q_low')
q_high=smtConfig.getint('Manifold_1', 'q_high')
示例4: drawBars
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
def drawBars(self,xvalues,yvalues,xlabel,ylabel,title,color):
logging.debug('>>')
logging.debug("Type: bars | title: %s"" | col: %s | xlabel: %s | ylabel: %s",
title, color, xlabel, ylabel)
self.removeVboxChildren()
#figure = Figure(figsize=(6,4), dpi=72)
figure = plt.figure()
logging.debug("Figure: %s", figure)
numCols=len(xvalues[0])
xmod = 0.4
self.showGraph=False
axis = figure.add_subplot(111)
logging.debug("Axis: %s", axis)
if len(xvalues) == 1: #One axis
barWidth = 0.8
barOffset = 0.1
logging.debug("One axis, barWidth %f, barOffset %f", barWidth, barOffset)
elif len(xvalues) == 2: #Twin axes
barWidth = 0.4
barOffset = 0.1
logging.debug("Twin axes, barWidth %f, barOffset %f", barWidth, barOffset)
else: #Error
logging.debug("Error: invalid number of axes" )
return
axis.set_xlabel(xlabel[0])
axis.set_ylabel(ylabel[0])
logging.debug("Labels set x: %s, y: %s", xlabel[0], ylabel[0])
xvals = [x+barOffset for x in range(0, numCols)]
yvals = [0] * numCols
for i in range(0, numCols):
yval = yvalues[0][i]
if float(yval) > 0.0:
self.showGraph=True
else:
yval = self.NEARLY_ZERO
yvals[i] = yval
if self.showGraph:
logging.debug("Drawing bars")
axis.bar(xvals, yvals, barWidth, color=color[0], align='edge')
else: #Only zero results
logging.debug("No results to draw")
pass
axis.grid(True)
axis.set_title("%s" %(title[0]))
logging.debug("Setting title to: %s", title[0])
for tl in axis.get_yticklabels():
logging.debug("Setting ticklabel color %s", color[0])
tl.set_color('%s' %color[0])
if len(xvalues) == 2: #Display twin axis
ax2 = axis.twinx()
logging.debug("Axis 2: Twin axis: %s", ax2)
xvals = [x+barOffset+barWidth for x in range(0, numCols)]
for i in range(0, numCols):
yval = yvalues[1][i]
if float(yval) > 0.0:
self.showGraph=True
else:
yval = self.NEARLY_ZERO
yvals[i] = yval
if self.showGraph:
logging.debug("Axis 2: Drawing bars")
ax2.bar(xvals, yvals, barWidth, color=color[1], align='edge')
logging.debug("Axis 2: Label set y: %s", ylabel[1])
ax2.set_ylabel(ylabel[1])
else: #Only zero results
logging.debug("Axis 2: No results to draw")
pass
for tl in ax2.get_yticklabels():
tl.set_color('%s' %color[1])
logging.debug("Axis 2: Setting ticklabel color %s", color[1])
_title = "%s vs %s" %(title[0],title[1])
logging.debug("Axis 2: Setting title to: %s", _title)
axis.set_title(_title)
logging.debug("Setting x ticks")
tickLocations = [x+0.5 for x in range(0, numCols)]
axis.set_xticks(tickLocations)
axis.set_xticklabels(xvalues[0])
logging.debug("Setting x limits")
axis.set_xlim(0, numCols)
canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea
logging.debug("Got canvas: %s", canvas)
canvas.show()
logging.debug("Adding canvas to vbox")
self.vbox.pack_start(canvas, True, True, 0)
#toolbar = NavigationToolbar(canvas, self.window)
#self.vbox.pack_start(toolbar, False, False)
for child in self.vbox.get_children():
logging.debug('Child available: %s', child)
logging.debug('<<')
示例5: drawPlot
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
def drawPlot(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None,xzones=None, ylimits=None, y1_linewidth=None):
logging.debug('>>')
logging.debug("Type: plot | title: %s | col: %s | xlabel: %s | ylabel: %s",
title, color, xlabel, ylabel)
logging.debug('xlabel: %s | ylabel: %s | title: %s', xlabel, ylabel, title)
self.removeVboxChildren()
figure = plt.Figure()
logging.debug("Figure: %s", figure)
#figure.clf()
i = 0
for value in xvalues:
if i<1:
logging.debug("i: %d, value: (%s) %s %s", i, value, xvalues, yvalues)
axis = figure.add_subplot(111)
logging.debug("Axis: %s", axis)
line = axis.plot(xvalues[i],yvalues[i], color=color[i])
logging.debug("Axis plotted, Line: %s", line)
if y1_linewidth is not None:
line[0].set_linewidth(y1_linewidth)
linewidth = line[0].get_linewidth()
axis.grid(True)
logging.debug("Axis grid on" )
for tl in axis.get_yticklabels():
tl.set_color('%s' %color[i])
logging.debug("Ticklabels color set" )
#Draw zones on graph, eg for each lap
if xzones is not None:
logging.debug("Setting xzones" )
for xzone in xzones:
if xzones.index(xzone) % 2:
zonecolor='b'
else:
zonecolor='g'
axis.axvspan(xzone[0], xzone[1], alpha=0.25, facecolor=zonecolor)
maxX = max(xvalues[i])
if i>=1:
ax2 = axis.twinx()
logging.debug("Axis2: Axis: %s", ax2)
ax2.plot(xvalues[i], yvalues[i], color=color[i])
logging.debug("Axis2: plotted" )
for tl in ax2.get_yticklabels():
tl.set_color('%s' %color[i])
logging.debug("Axis2: Ticklabels color set" )
maxXt = max(xvalues[i])
if maxXt > maxX:
maxX = maxXt
axis.set_xlabel(xlabel[i])
logging.debug("X label set" )
i+=1
axis.set_xlim(0, maxX)
if (len(xvalues)>1):
axis.set_title("%s vs %s" %(ylabel[0],ylabel[1]))
else:
axis.set_title("%s" %(ylabel[0]))
ylim_min, ylim_max = axis.get_ylim()
if ylimits is not None:
logging.debug("Using ylimits: %s", ylimits)
if ylimits[0] is not None:
ylim_min = ylimits[0]
if ylimits[1] is not None:
ylim_max = ylimits[1]
axis.set_ylim(ylim_min, ylim_max)
canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea
logging.debug("Canvas: %s", canvas)
canvas.show()
self.vbox.pack_start(canvas, True, True, 0)
toolbar = NavigationToolbar(canvas, self.window)
self.vbox.pack_start(toolbar, False, False, 0)
for child in self.vbox.get_children():
logging.debug('Child available: %s', child)
logging.debug('<<')
return {'y1_min': ylim_min, 'y1_max': ylim_max, 'y1_linewidth': linewidth}
示例6: __init__
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
class DrawArea:
def __init__(self, vbox = None, window = None):
logging.debug('>>')
#self.figure = Figure(figsize=(6,4), dpi=72)
#self.axis = self.figure.add_subplot(111)
self.vbox = vbox
self.window = window
#self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
#self.drawDefault()
self.NEARLY_ZERO = 0.0000000000000000000001
logging.debug('<<')
def stadistics(self,type,xvalues,yvalues,xlabel,ylabel,title,color=None,zones=None):
logging.debug('>>')
if len(xvalues[0]) < 1:
#self.drawDefault()
return False
#logging.debug('xvalues: '+str(xvalues))
#logging.debug('yvalues: '+str(yvalues))
#logging.debug("Type: "+type+" | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel))
if type == "bars":
self.drawBars(xvalues,yvalues,xlabel,ylabel,title,color)
elif type == "plot":
self.drawPlot(xvalues,yvalues,xlabel,ylabel,title,color,zones)
elif type == "pie" or type == "histogram":
self.drawZones(type,xvalues,yvalues,xlabel,ylabel,title,color,zones)
logging.debug('<<')
def drawBars(self,xvalues,yvalues,xlabel,ylabel,title,color):
logging.debug('>>')
logging.debug("Type: bars | title: %s"" | col: %s | xlabel: %s | ylabel: %s",
title, color, xlabel, ylabel)
self.removeVboxChildren()
#figure = Figure(figsize=(6,4), dpi=72)
figure = plt.figure()
logging.debug("Figure: %s", figure)
numCols=len(xvalues[0])
xmod = 0.4
self.showGraph=False
axis = figure.add_subplot(111)
logging.debug("Axis: %s", axis)
if len(xvalues) == 1: #One axis
barWidth = 0.8
barOffset = 0.1
logging.debug("One axis, barWidth %f, barOffset %f", barWidth, barOffset)
elif len(xvalues) == 2: #Twin axes
barWidth = 0.4
barOffset = 0.1
logging.debug("Twin axes, barWidth %f, barOffset %f", barWidth, barOffset)
else: #Error
logging.debug("Error: invalid number of axes" )
return
axis.set_xlabel(xlabel[0])
axis.set_ylabel(ylabel[0])
logging.debug("Labels set x: %s, y: %s", xlabel[0], ylabel[0])
xvals = [x+barOffset for x in range(0, numCols)]
yvals = [0] * numCols
for i in range(0, numCols):
yval = yvalues[0][i]
if float(yval) > 0.0:
self.showGraph=True
else:
yval = self.NEARLY_ZERO
yvals[i] = yval
if self.showGraph:
logging.debug("Drawing bars")
axis.bar(xvals, yvals, barWidth, color=color[0], align='edge')
else: #Only zero results
logging.debug("No results to draw")
pass
axis.grid(True)
axis.set_title("%s" %(title[0]))
logging.debug("Setting title to: %s", title[0])
for tl in axis.get_yticklabels():
logging.debug("Setting ticklabel color %s", color[0])
tl.set_color('%s' %color[0])
if len(xvalues) == 2: #Display twin axis
ax2 = axis.twinx()
logging.debug("Axis 2: Twin axis: %s", ax2)
xvals = [x+barOffset+barWidth for x in range(0, numCols)]
for i in range(0, numCols):
yval = yvalues[1][i]
if float(yval) > 0.0:
self.showGraph=True
else:
yval = self.NEARLY_ZERO
yvals[i] = yval
if self.showGraph:
logging.debug("Axis 2: Drawing bars")
ax2.bar(xvals, yvals, barWidth, color=color[1], align='edge')
logging.debug("Axis 2: Label set y: %s", ylabel[1])
ax2.set_ylabel(ylabel[1])
else: #Only zero results
logging.debug("Axis 2: No results to draw")
pass
for tl in ax2.get_yticklabels():
#.........这里部分代码省略.........
示例7: drawStackedBars
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
def drawStackedBars(self,xvalues,yvalues,ylabel,title, valuesAreTime=False, colors={}):
'''function to draw stacked bars
xvalues needs to be a list of lists of strings, e.g. [0]["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
yvalues needs to be a list of dicts e.g. [0]{'Kayak': {'Tue': 10.08, 'Fri': 17.579999999999998, 'Thu': 15.66, 'Sat': 30.619999999999997}, {'Run': {'Mon': 9.65, 'Sun': 15.59}}
'''
#TODO tidy
logging.debug('>>')
logging.debug("Title: %s", title)
logging.debug("X values received: %s", xvalues)
logging.debug("Y values received: %s", yvalues)
self.removeVboxChildren()
#Check how many axes to draw
if len(xvalues) == 1: #One axis
barWidth = 0.8
barOffset = 0.1
elif len(xvalues) == 2: #Twin axes
barWidth = 0.4
barOffset = 0.1
else: #Error
return
keys = list(yvalues[0].keys()) # days of the week
numRows = len(keys)
numCols = len(xvalues[0])
if numRows == 0:
return
width = .8
#figure = plt.figure(figsize=(6,4), dpi=72)
figure = plt.figure()
logging.debug("Figure: %s", figure)
axis = plt.subplot(111)
ybottoms = [0] * numCols
yheights = [0] * numCols
inds = range(0, numCols)
xvals = [x+barOffset for x in range(0, numCols)]
cellText = []
self.showGraph=False
for k in colors:
if colors[k]==None: colors[k]=''
#Display first axis
xticks = []
for key in keys:
logging.debug("Day of the week: %s", key)
for ind in inds:
ybottoms[ind] += yheights[ind]
yheights[ind] = 0 #Zero heights
color = "#"+colors.get(key, '')
if len(color)<2:
color = self.getColor(keys.index(key))
for xvalue in xvalues[0]:
index = xvalues[0].index(xvalue)
if xvalue in yvalues[0][key]:
height = yvalues[0][key][xvalue]
if float(height) > 0.0:
self.showGraph=True
else:
height = self.NEARLY_ZERO
yheights[index] = height
cellText.append([self.fmtTableText(x, valuesAreTime[0]) for x in yheights])
if self.showGraph:
axis.bar(xvals, yheights, bottom=ybottoms, width=barWidth, color=color, align='edge', label=key)
else: #Only zero results
pass
axis.set_xticklabels('' * len(xvalues[0]))
axis.set_ylabel(ylabel[0])
if len(xvalues) == 1:
plt.title(title[0])
axis.legend(loc=0)
axis.set_xlim(0,numCols)
logging.debug("X values first axis: %s", xvals)
logging.debug("Y values first axis: %s", yheights)
#Display twin axis
if len(xvalues) == 2:
self.showGraph=False
ax2 = axis.twinx()
keys = list(yvalues[1].keys())
ybottoms = [0] * numCols
yheights = [self.NEARLY_ZERO] * numCols
for key in keys:
for ind in inds:
ybottoms[ind] += yheights[ind]
yheights[ind] = 0.0 #Zero heights
color = "#"+colors.get(key, '')
if len(color)<2:
color = self.getColor(keys.index(key))
for xvalue in xvalues[0]:
index = xvalues[0].index(xvalue)
if xvalue in yvalues[1][key]:
height = yvalues[1][key][xvalue]
if float(height) > 0.0:
self.showGraph=True
else:
height = self.NEARLY_ZERO
#.........这里部分代码省略.........
示例8: CampaignGraph
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
class CampaignGraph(object):
title = 'Unknown'
_graph_id = None
table_subscriptions = []
def __init__(self, config, parent, size_request=None):
self.config = config
self.parent = parent
self.figure, ax = pyplot.subplots()
self.axes = self.figure.get_axes()
self.canvas = FigureCanvas(self.figure)
self.manager = None
if size_request:
self.canvas.set_size_request(*size_request)
self.canvas.mpl_connect('button_press_event', self.mpl_signal_canvas_button_pressed)
self.canvas.show()
self.navigation_toolbar = NavigationToolbar(self.canvas, self.parent)
self.navigation_toolbar.hide()
self.popup_menu = Gtk.Menu.new()
menu_item = Gtk.MenuItem.new_with_label('Export')
menu_item.connect('activate', self.signal_activate_popup_menu_export)
self.popup_menu.append(menu_item)
menu_item = Gtk.MenuItem.new_with_label('Refresh')
menu_item.connect('activate', lambda action: self.refresh())
self.popup_menu.append(menu_item)
menu_item = Gtk.CheckMenuItem.new_with_label('Show Toolbar')
menu_item.connect('toggled', self.signal_toggled_popup_menu_show_toolbar)
self.popup_menu.append(menu_item)
self.popup_menu.show_all()
@classmethod
def get_graph_id(klass):
return klass._graph_id
def make_window(self):
if self.manager == None:
self.manager = FigureManager(self.canvas, 0)
window = self.manager.window
window.set_transient_for(self.parent)
window.set_title(self.title)
return window
def mpl_signal_canvas_button_pressed(self, event):
if event.button != 3:
return
pos_func = lambda m, d: (event.x, event.y, True)
self.popup_menu.popup(None, None, None, None, event.button, Gtk.get_current_event_time())
return True
def signal_activate_popup_menu_export(self, action):
dialog = gui_utilities.UtilityFileChooser('Export Graph', self.parent)
file_name = self.config['campaign_name'] + '.png'
response = dialog.run_quick_save(file_name)
dialog.destroy()
if not response:
return
destination_file = response['target_filename']
self.figure.savefig(destination_file, format='png')
def signal_toggled_popup_menu_show_toolbar(self, widget):
if widget.get_property('active'):
self.navigation_toolbar.show()
else:
self.navigation_toolbar.hide()
def load_graph(self):
self.refresh()
def refresh(self, info_cache=None):
info_cache = (info_cache or {})
if not self.parent.rpc:
return info_cache
for table in self.table_subscriptions:
if not table in info_cache:
info_cache[table] = list(self.parent.rpc.remote_table('campaign/' + table, self.config['campaign_id']))
map(lambda ax: ax.clear(), self.axes)
self._load_graph(info_cache)
self.canvas.draw()
return info_cache
示例9: draw
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
def draw(self, datalist=None, box=None, figure=None, title=None, y2=False, xgrid=False, ygrid=False):
'''
Draw a graph using supplied information into supplied Gtk.box
datalist = populated graphdata class (required)
box = Gtk.box object (required)
figure = matplotlib figure (optional) if supplied will add graph to this figure
title =
y2 =
return = figure
'''
logging.debug('>>')
if box is None:
logging.error("Must supply a vbox or hbox to display the graph")
return
#Check if have a graph object
if figure is None:
#No figure, so create figure
figure = plt.figure()
self.ax1 = plt.axes()
#Reset second axis
self.ax2 = None
#Remove any existing plots
for child in box.get_children():
logging.debug('Removing box child: %s', child)
box.remove(child)
if datalist is None:
logging.debug("drawPlot called with no data")
return figure
if y2 and self.ax2 is None:
self.ax2 = plt.twinx()
#Create canvas
canvas = FigureCanvasGTK(figure) # a Gtk.DrawingArea
canvas.show()
#Display title etc
if datalist.xlabel is not None:
plt.xlabel(datalist.xlabel)
if title is not None:
plt.title(title)
#Display grid
if y2 and ygrid:
self.ax2.grid(True)
elif self.ax1 and ygrid:
self.ax1.grid(True)
plt.gca().xaxis.grid(xgrid)
#Removed as now in legend
#plt.ylabel(datalist.ylabel)
#Determine graph type....
#print "Got graphtype: %s" % datalist.graphType
#print datalist.x_values
#print datalist.y_values
#print datalist.linewidth
#print datalist.linecolor
#print datalist.ylabel
if datalist.graphType == "plot":
#Plot data
if not y2:
#plt.plot(datalist.x_values, datalist.y_values, linewidth=datalist.linewidth, color=datalist.linecolor, label=datalist.ylabel )
self.ax1.plot(datalist.x_values, datalist.y_values, linewidth=datalist.linewidth, color=datalist.linecolor, label=datalist.ylabel )
else:
self.ax2.plot(datalist.x_values, datalist.y_values, linewidth=datalist.linewidth, color=datalist.y2linecolor, label=datalist.ylabel )
elif datalist.graphType == "bar":
if not y2:
self.ax1.bar(datalist.x_values, datalist.y_values, datalist.bar_widths, datalist.bar_bottoms, color=datalist.linecolor, label=datalist.ylabel, alpha=0.5)
else:
self.ax2.bar(datalist.x_values, datalist.y_values, datalist.bar_widths, datalist.bar_bottoms, color=datalist.y2linecolor, label=datalist.ylabel, alpha=0.5)
elif datalist.graphType == "vspan":
i = 0
while i < len(datalist.x_values):
#print datalist.x_values[i] , datalist.bar_widths[i]
if not y2:
self.ax1.axvspan(datalist.x_values[i], datalist.x_values[i]+datalist.bar_widths[i], alpha=0.15, facecolor=datalist.linecolor)
else:
self.ax2.axvspan(datalist.x_values[i], datalist.x_values[i]+datalist.bar_widths[i], alpha=0.15, facecolor=datalist.y2linecolor)
i += 1
elif datalist.graphType == "hspan":
i = 0
while i < len(datalist.x_values):
#print datalist.x_values[i] , datalist.y_values[i], datalist.labels[i], datalist.colors[i]
if not y2:
self.ax1.axhspan(datalist.x_values[i], datalist.y_values[i], alpha=0.25, facecolor=datalist.colors[i], label=datalist.labels[i])
else:
self.ax2.axhspan(datalist.x_values[i], datalist.y_values[i], alpha=0.25, facecolor=datalist.colors[i], label=datalist.labels[i])
i += 1
elif datalist.graphType == "date":
if not y2:
self.ax1.plot_date(datalist.x_values, datalist.y_values, color=datalist.linecolor, label=datalist.ylabel, alpha=0.5)
else:
self.ax2.plot_date(datalist.x_values, datalist.y_values, color=datalist.y2linecolor, label=datalist.ylabel, alpha=0.5)
else:
logging.error("Unknown/unimplemented graph type: %s", datalist.graphType)
return figure
#Set axis limits
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg [as 别名]
# 或者: from matplotlib.backends.backend_gtk3agg.FigureCanvasGTK3Agg import show [as 别名]
#.........这里部分代码省略.........
if self.number_of_subplots <= 1:
self.num_rows = 1
self.main_title_fontsize = 24
matplotlib.rcParams['legend.fontsize'] = 12
matplotlib.rcParams['axes.labelsize'] = 12
matplotlib.rcParams['axes.titlesize'] = 10
matplotlib.rcParams['xtick.labelsize'] = 10
matplotlib.rcParams['ytick.labelsize'] = 10
matplotlib.rcParams['figure.subplot.top'] = 0.8 # single figure plots have a larger title so require more space at the top.
elif ((self.number_of_subplots >= 2) and (self.number_of_subplots <= 6 )):
self.num_rows = 2
self.main_title_fontsize = 18
matplotlib.rcParams['legend.fontsize'] = 10
matplotlib.rcParams['axes.labelsize'] = 10
matplotlib.rcParams['axes.titlesize'] = 11
matplotlib.rcParams['xtick.labelsize'] = 8
matplotlib.rcParams['ytick.labelsize'] = 8
#self.x_axes_ticks = P.arange(0,25,4)
else:
self.num_rows = 3
self.main_title_fontsize = 16
matplotlib.rcParams['legend.fontsize'] = 8
matplotlib.rcParams['axes.labelsize'] = 8
matplotlib.rcParams['axes.titlesize'] = 10
matplotlib.rcParams['xtick.labelsize'] = 6
matplotlib.rcParams['ytick.labelsize'] = 6
#self.x_axes_ticks = P.arange(0,25,4)
self.num_cols = int(math.ceil(float(self.number_of_subplots)/float(self.num_rows)))
self.fig=Figure()
self.main_title_label = self.fig.suptitle(str(self.image_defs['title']), fontsize=self.main_title_fontsize)
if projection == 'ortho':
self.show_subplot_frame = False
for plot_ctr, vg_file in enumerate(vg_files):
points = np.zeros([grid,grid], float)
lons = np.arange(area_rect.get_sw_lon(), area_rect.get_ne_lon()+0.001,(area_rect.get_ne_lon()-area_rect.get_sw_lon())/float(grid-1))
lons[-1] = min(180.0, lons[-1])
lats = np.arange(area_rect.get_sw_lat(), area_rect.get_ne_lat()+0.001,(area_rect.get_ne_lat()-area_rect.get_sw_lat())/float(grid-1))
lats[-1] = min(90.0, lats[-1])
ax = self.fig.add_subplot(self.num_rows,
self.num_cols,
plot_ctr+1,
frame_on = self.show_subplot_frame,
axisbg = 'white')
self.subplots.append(ax)
ax.label_outer()
if in_file.endswith('.vgz'):
base_filename = get_base_filename(in_file)
zf = zipfile.ZipFile(in_file)
vgFile = io.TextIOWrapper(zf.open("{:s}.vg{:d}".format(base_filename, vg_file)), 'utf-8')
else:
vgFile = open("{:s}.vg{:d}".format(os.path.splitext(in_file)[0], vg_file))
pattern = re.compile(r"[a-z]+")
for line in vgFile:
match = pattern.search( line )
if not match:
value = float(line[int(self.image_defs['first_char']):int(self.image_defs['last_char'])])
# TODO Does this need to be normalised here if it's also being done in the plot?
value = max(self.image_defs['min'], value)