本文整理汇总了Python中matplotlib.figure.Figure.set_facecolor方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.set_facecolor方法的具体用法?Python Figure.set_facecolor怎么用?Python Figure.set_facecolor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.set_facecolor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reports_pie
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def reports_pie(request,scope):
month, year, late , dates_gc = current_reporting_period()
period = (dates_gc[0],dates_gc[1])
completed = len(scope.current_entries())
incomplete = len(scope.health_posts()) - len(scope.current_entries())
fig = Figure()
ax=fig.add_subplot(111, axisbg='r')
fig.set_figheight(2)
fig.set_figwidth(2)
fig.set_facecolor('w')
labels = 'Completed', 'Incomlete'
fracs = [completed,incomplete]
explode=(0,0.01)
pie(fracs, explode=explode, labels=None,colors=('g','r'), autopct='%1.1f%%', shadow=True)
title('Reports..', bbox={'facecolor':'0.5', 'pad':5})
ax.pie(fracs, explode=explode, labels=None,colors=('#52E060','#F7976E'), shadow=True)
canvas=FigureCanvas(fig)
response=HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例2: plot
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def plot(title='title',xlab='x',ylab='y',mode='plot',
data={'xxx':[(0,0),(1,1),(1,2),(3,3)],
'yyy':[(0,0,.2,.2),(2,1,0.2,0.2),(2,2,0.2,0.2),(3,3,0.2,0.3)]}):
fig=Figure()
fig.set_facecolor('white')
ax=fig.add_subplot(111)
if title: ax.set_title(title)
if xlab: ax.set_xlabel(xlab)
if ylab: ax.set_ylabel(ylab)
legend=[]
keys=sorted(data)
for key in keys:
stream = data[key]
(x,y)=([],[])
for point in stream:
x.append(point[0])
y.append(point[1])
if mode=='plot':
ell=ax.plot(x, y)
legend.append((ell,key))
if mode=='hist':
ell=ax.hist(y,20)
if legend:
ax.legend([x for (x,y) in legend], [y for (x,y) in legend],
'upper right', shadow=True)
canvas=FigureCanvas(fig)
stream=cStringIO.StringIO()
canvas.print_png(stream)
return stream.getvalue()
示例3: scatter
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def scatter(title="title", xlab="x", ylab="y", data=None):
if data == None:
r = random.random
data = [(r() * 10, r() * 10, r(), r(), r(), r(), r()) for i in range(100)]
figure = Figure()
figure.set_facecolor("white")
axes = figure.add_subplot(111)
if title:
axes.set_title(title)
if xlab:
axes.set_xlabel(xlab)
if ylab:
axes.set_ylabel(ylab)
for i, p in enumerate(data):
p = list(p)
while len(p) < 4:
p.append(0.01)
e = Ellipse(xy=p[:2], width=p[2], height=p[3])
axes.add_artist(e)
e.set_clip_box(axes.bbox)
e.set_alpha(0.5)
if len(p) == 7:
e.set_facecolor(p[4:])
data[i] = p
axes.set_xlim(min(p[0] - p[2] for p in data), max(p[0] + p[2] for p in data))
axes.set_ylim(min(p[1] - p[3] for p in data), max(p[1] + p[3] for p in data))
canvas = FigureCanvas(figure)
stream = cStringIO.StringIO()
canvas.print_png(stream)
return stream.getvalue()
示例4: __init__
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def __init__(self, masterWindow, style='default'):
self.masterWindow = masterWindow
self.style = style
specArea = masterWindow.ui.specArea
#create the canvas for spectral plotting
bfig = Figure()
bfig.set_facecolor('white')
self.canvas = FigureCanvasQTAgg(bfig)
specArea.addWidget(self.canvas)
#TODO: next line is slowest in module
self.plt = bfig.add_subplot(111, frameon=False)
self.plt.xaxis.set_ticks_position('bottom')
self.plt.yaxis.set_ticks_position('none')
self.plt.xaxis.set_tick_params(which='both', direction='out')
# create a hidden NavigationBar to handle panning/zooming
self.navbar = NavigationToolbar2QT(self.canvas, None)
self.ev_time = 0, None, None
self.canvas.mpl_connect('button_press_event', self.mousedown)
self.canvas.mpl_connect('button_release_event', self.mouseup)
self.canvas.mpl_connect('scroll_event', self.mousescroll)
self.mainscan, self.prevscan = None, None
self.libscans = []
示例5: __init__
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def __init__(self, parent, red_farred):
super(GraphPanel, self).__init__(parent, -1)
self.SetBackgroundColour((218,238,255))
self.SetWindowStyle(wx.RAISED_BORDER)
figure = Figure()
figure.set_facecolor(color='#daeeff')
sizer = wx.BoxSizer(wx.VERTICAL)
self.axes = figure.add_subplot(111)
self.x_data = range(340, 821)
self.axes.plot(self.x_data, [0] * 481, label='Scan 0')
self.axes.legend(loc=1)
self.canvas = FigureCanvasWxAgg(self, -1, figure)
figure.tight_layout(pad=2.0)
sizer.Add(self.canvas, 1, wx.EXPAND | wx.ALL)
sizer.AddSpacer(20)
add_toolbar(sizer, self.canvas)
self.SetSizer(sizer)
self.canvas.draw()
cid1 = self.canvas.mpl_connect('motion_notify_event', self.on_movement)
cid2 = self.canvas.mpl_connect('button_press_event', self.on_press)
cid3 = self.canvas.mpl_connect('scroll_event', self.on_scroll)
self.integ_lines = []
self.fractional_lines = []
self.plot_unit = -1
self.plot_mode = -1
self.text = None
self.x_label = X_LABEL
self.red_farred = red_farred
示例6: __init__
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def __init__(self, masterWindow, style=None, scheme=None):
self.masterWindow = masterWindow
self.legend = False
plotArea = masterWindow.ui.plotArea
#create the plotting canvas and its toolbar and add them
tfig = Figure()
tfig.set_facecolor('white')
self.canvas = FigureCanvasQTAgg(tfig)
self.navbar = AstonNavBar(self.canvas, masterWindow)
plotArea.addWidget(self.navbar)
plotArea.addWidget(self.canvas)
#TODO this next line is the slowest in this module
#self.plt = tfig.add_subplot(111, frameon=False)
self.plt = tfig.add_axes((0.05, 0.1, 0.9, 0.85), frame_on=False)
self.plt.xaxis.set_ticks_position('none')
self.plt.yaxis.set_ticks_position('none')
self.patches = []
self.cb = None
#TODO: find a way to make the axes fill the figure properly
#tfig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.95)
#tfig.tight_layout(pad=2)
self.canvas.setFocusPolicy(Qt.ClickFocus)
self.canvas.mpl_connect('button_press_event', self.mousedown)
self.canvas.mpl_connect('button_release_event', self.mouseup)
self.canvas.mpl_connect('scroll_event', self.mousescroll)
self.highlight = None
示例7: MplCanvas
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
class MplCanvas(FigureCanvas):
def __init__(self, figsize=(8, 6), dpi=80):
self.fig = Figure(figsize=figsize, dpi=dpi)
self.fig.subplots_adjust(wspace=0, hspace=0, left=0, right=1.0, top=1.0, bottom=0)
self.ax = self.fig.add_subplot(111, frameon=False)
self.ax.patch.set_visible(False)
self.ax.set_axis_off()
FigureCanvas.__init__(self, self.fig)
FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
#self.setAlpha(0.0)
def saveFig(self, str_io_buf):
self.setAlpha(0.0)
self.fig.savefig(str_io_buf, transparent=True, frameon=False, format='png')
# 140818 Save file to StringIO Buffer not disk file
def getFig(self):
return self.fig
def setAlpha(self, value):
self.fig.patch.set_alpha(value)
self.ax.patch.set_alpha(value)
self.ax.set_axis_off()
def set_face_color(self, color):
self.fig.set_facecolor(color) # "#000000"
示例8: rate_stats
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def rate_stats():
try:
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from cStringIO import StringIO
response.headers['Content-Type']='image/png'
title='USD Bitcoin Conversion'
xlab='Time'
ylab='Price'
data_t = []
data_r = []
rates = db(db.rates).select()
for rate in rates:
data_t.append(rate.time);
data_r.append(rate.value);
fig=Figure()
fig.set_facecolor('white')
ax=fig.add_subplot(111)
if title: ax.set_title(title)
if xlab: ax.set_xlabel(xlab)
if ylab: ax.set_ylabel(ylab)
image=ax.plot_date(data_t,data_r)
#image.set_interpolation('bilinear')
canvas=FigureCanvas(fig)
stream=StringIO()
canvas.print_png(stream)
return stream.getvalue()
except ImportError:
return dict(mess="Couldn't Plot server requires matplotlib")
示例9: test_repeated_save_with_alpha
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def test_repeated_save_with_alpha():
# We want an image which has a background color of bluish green, with an
# alpha of 0.25.
fig = Figure([1, 0.4])
canvas = FigureCanvas(fig)
fig.set_facecolor((0, 1, 0.4))
fig.patch.set_alpha(0.25)
# The target color is fig.patch.get_facecolor()
_, img_fname = tempfile.mkstemp(suffix='.png')
try:
fig.savefig(img_fname,
facecolor=fig.get_facecolor(),
edgecolor='none')
# Save the figure again to check that the
# colors don't bleed from the previous renderer.
fig.savefig(img_fname,
facecolor=fig.get_facecolor(),
edgecolor='none')
# Check the first pixel has the desired color & alpha
# (approx: 0, 1.0, 0.4, 0.25)
assert_array_almost_equal(tuple(imread(img_fname)[0, 0]),
(0.0, 1.0, 0.4, 0.250),
decimal=3)
finally:
os.remove(img_fname)
示例10: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
class PlotPanel(wx.Panel):
"""
The PlotPanel has a Figure and a Canvas. OnSize events simply set a
flag, and the actual resizing of the figure is triggered by an Idle event.
"""
def __init__(self, parent, obj_id):
# initialize Panel
wx.Panel.__init__(self, parent, obj_id)
# initialize matplotlib stuff
self.figure = Figure(None, None)
self.canvas = FigureCanvasWxAgg(self, wx.ID_ANY, self.figure)
rgbtuple = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE).Get()
clr = [c / 255.0 for c in rgbtuple]
self.figure.set_facecolor(clr)
self.figure.set_edgecolor(clr)
self.canvas.SetBackgroundColour(wx.Colour(*rgbtuple))
self.Bind(wx.EVT_SIZE, self._on_size)
def _on_size(self, event):
self._set_size()
def _set_size(self):
pixels = tuple(self.GetClientSize())
self.SetSize(pixels)
self.canvas.SetSize(pixels)
self.figure.set_size_inches(float(pixels[0]) / self.figure.get_dpi(), float(pixels[1]) / self.figure.get_dpi())
def draw(self):
pass # abstract, to be overridden by child classes
示例11: exchange_stats
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def exchange_stats():
try:
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from cStringIO import StringIO
response.headers['Content-Type']='image/png'
title='Exchanges'
xlab='Time'
ylab='Value'
data_t = []
data_v = []
exchanges = db(db.exchange).select()
for exchange in exchanges:
data_t.append(datetime.datetime.fromtimestamp(exchange.time));
data_v.append(exchange.value);
fig=Figure()
fig.set_facecolor('white')
ax=fig.add_subplot(111)
if title: ax.set_title(title)
if xlab: ax.set_xlabel(xlab)
if ylab: ax.set_ylabel(ylab)
image=ax.plot_date(data_t,data_v)
canvas=FigureCanvas(fig)
stream=StringIO()
canvas.print_png(stream)
return stream.getvalue()
except ImportError:
return dict(mess="Couldn't Plot server requires matplotlib")
示例12: get_bottles_user_pie_chart
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def get_bottles_user_pie_chart(request, bottleId):
fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_axes([0,0,1,1])
ax.axis('equal')
drinks = Glass.objects.filter(bottle__id=bottleId)
drinksVolume = 0.0
users = dict()
labels = []
fracs = []
explode = []
for drink in drinks:
if drink.user in users:
users[drink.user] = users[drink.user] + drink.volume
else:
users[drink.user] = drink.volume
drinksVolume = drinksVolume + drink.volume
for key in users:
labels.append(key)
fracs.append(users[key])
explode.append(0.0)
ax.pie(fracs, explode=explode, colors=('#87F881', '#8F96F4', '#FFDE85', '#FF8488', 'r', 'g', 'b'), \
labels=labels, autopct='%1.0f%%', shadow=False)
fig.set_facecolor('white')
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例13: bar_plot
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def bar_plot(d, labels):
colors = itertools.cycle(['b', 'g', 'r', 'c', 'm', 'y', 'k'])
fig=Figure(figsize=(8, 6), dpi=200)
fig.set_facecolor('white')
fig.subplots_adjust(bottom=0.30)
ax=fig.add_subplot(111)
ax.set_title("")
ax.set_ylabel('Factor values')
#ax.grid(which='major')
bottom = None
for col in d.columns:
if bottom is None:
bottom = 0*d[col]
ax.bar(range(len(d[col])), d[col], align='center', bottom=bottom,
label=labels[col], color=colors.next(), alpha=0.6)
bottom += d[col]
ax.set_xticks(range(len(d[col])))
ax.set_xlim([-0.5, len(d[col])])
ax.set_xticklabels([unicode(el) for el in d[col].index], size='x-small',
rotation='vertical')
leg = ax.legend(loc='best', fancybox=True, prop={'size':9})
leg.get_frame().set_alpha(0.5)
canvas=FigureCanvas(fig)
stream=cStringIO.StringIO()
canvas.print_png(stream, bbox_inches='tight')
return stream.getvalue()
示例14: test_repeated_save_with_alpha
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
def test_repeated_save_with_alpha():
# We want an image which has a background color of bluish green, with an
# alpha of 0.25.
fig = Figure([1, 0.4])
fig.set_facecolor((0, 1, 0.4))
fig.patch.set_alpha(0.25)
# The target color is fig.patch.get_facecolor()
buf = io.BytesIO()
fig.savefig(buf,
facecolor=fig.get_facecolor(),
edgecolor='none')
# Save the figure again to check that the
# colors don't bleed from the previous renderer.
buf.seek(0)
fig.savefig(buf,
facecolor=fig.get_facecolor(),
edgecolor='none')
# Check the first pixel has the desired color & alpha
# (approx: 0, 1.0, 0.4, 0.25)
buf.seek(0)
assert_array_almost_equal(tuple(imread(buf)[0, 0]),
(0.0, 1.0, 0.4, 0.250),
decimal=3)
示例15: PlotPanel
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_facecolor [as 别名]
class PlotPanel(wx.Panel):
"""The PlotPanel has a Figure and a Canvas. OnSize events simply set a
flag, and the actual resizing of the figure is triggered by an Idle event."""
def __init__(self, parent, color=None, dpi=None, **kwargs):
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
self.parent = parent
# initialize Panel
if 'id' not in kwargs.keys():
kwargs['id'] = wx.ID_ANY
if 'style' not in kwargs.keys():
kwargs['style'] = wx.NO_FULL_REPAINT_ON_RESIZE
wx.Panel.__init__(self, parent, **kwargs)
# initialize matplotlib stuff
self.figure = Figure(None, dpi)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.SetColor(color)
self._SetSize()
self.initial_draw()
self._resizeflag = False
self._redrawflag = False
self.Bind(wx.EVT_IDLE, self._onIdle)
self.Bind(wx.EVT_SIZE, self._onSize)
def SetColor(self, rgbtuple=None):
"""Set figure and canvas colours to be the same."""
if rgbtuple is None:
rgbtuple = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE).Get()
clr = [c/255. for c in rgbtuple]
self.figure.set_facecolor(clr)
self.figure.set_edgecolor(clr)
self.canvas.SetBackgroundColour(wx.Colour(*rgbtuple))
def _onSize(self, event):
self._resizeflag = True
def _onIdle(self, evt):
with draw_lock:
if self._resizeflag:
self._resizeflag = False
self._SetSize()
if self._redrawflag:
self._redrawflag = False
self.canvas.draw()
def _SetSize(self):
# When drawing from another thread, I think this may need a lock
pixels = tuple(self.parent.GetClientSize())
self.SetSize(pixels)
self.canvas.SetSize(pixels)
self.figure.set_size_inches(float(pixels[0])/self.figure.get_dpi(),
float(pixels[1])/self.figure.get_dpi())
def initial_draw(self): pass # abstract, to be overridden by child classes