本文整理汇总了Python中matplotlib.figure.Figure.set_figwidth方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.set_figwidth方法的具体用法?Python Figure.set_figwidth怎么用?Python Figure.set_figwidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.set_figwidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quiver_response
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def quiver_response(lon, lat, dx, dy, request, dpi=None):
dpi = dpi or 80.
bbox = request.GET['bbox']
width = request.GET['width']
height = request.GET['height']
colormap = request.GET['colormap']
colorscalerange = request.GET['colorscalerange']
vectorscale = request.GET['vectorscale']
cmin = colorscalerange.min
cmax = colorscalerange.max
crs = request.GET['crs']
unit_vectors = None # We don't support requesting these yet, but wouldn't be hard
EPSG4326 = pyproj.Proj(init='EPSG:4326')
x, y = pyproj.transform(EPSG4326, crs, lon, lat) # TODO order for non-inverse?
fig = Figure(dpi=dpi, facecolor='none', edgecolor='none')
fig.set_alpha(0)
fig.set_figheight(height/dpi)
fig.set_figwidth(width/dpi)
ax = fig.add_axes([0., 0., 1., 1.], xticks=[], yticks=[])
ax.set_axis_off()
mags = np.sqrt(dx**2 + dy**2)
cmap = mpl.cm.get_cmap(colormap)
if request.GET['logscale'] is True:
norm_func = mpl.colors.LogNorm
else:
norm_func = mpl.colors.Normalize
# Set out of bound data to NaN so it shows transparent?
# Set to black like ncWMS?
# Configurable by user?
if cmin is not None and cmax is not None:
mags[mags > cmax] = cmax
mags[mags < cmin] = cmin
norm = norm_func(vmin=cmin, vmax=cmax)
else:
norm = norm_func()
# plot unit vectors
if unit_vectors:
ax.quiver(x, y, dx/mags, dy/mags, mags, cmap=cmap, norm=norm, scale=vectorscale)
else:
ax.quiver(x, y, dx, dy, mags, cmap=cmap, norm=norm, scale=vectorscale)
ax.set_xlim(bbox.minx, bbox.maxx)
ax.set_ylim(bbox.miny, bbox.maxy)
ax.set_frame_on(False)
ax.set_clip_on(False)
ax.set_position([0., 0., 1., 1.])
canvas = FigureCanvasAgg(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例2: getImage
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def getImage(self):
figure = Figure()
axes = figure.add_subplot(111)
yAxes = self.signal_read()
xAxes = [1]
aux = 1
for x in range (0, len(yAxes)-1):
aux += 1.0/self.sampleRate
xAxes.append(aux)
axes.plot(xAxes, yAxes)
canvas = FigureCanvas(figure)
figure.set_figwidth(6)
figure.set_figheight(2)
figure.savefig(self.fileImage)
fig = QLabel()
fig.setPixmap(QPixmap(self.fileImage))
fig.setFixedSize(600, 200)
return fig
示例3: tricontouring_response
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def tricontouring_response(tri_subset, data, request, dpi=None):
"""
triang_subset is a matplotlib.Tri object in lat/lon units (will be converted to projected coordinates)
xmin, ymin, xmax, ymax is the bounding pox of the plot in PROJETED COORDINATES!!!
request is the original getMap request object
"""
dpi = dpi or 80.
bbox = request.GET['bbox']
width = request.GET['width']
height = request.GET['height']
colormap = request.GET['colormap']
colorscalerange = request.GET['colorscalerange']
cmin = colorscalerange.min
cmax = colorscalerange.max
crs = request.GET['crs']
nlvls = request.GET['numcontours']
EPSG4326 = pyproj.Proj(init='EPSG:4326')
tri_subset.x, tri_subset.y = pyproj.transform(EPSG4326, crs, tri_subset.x, tri_subset.y)
fig = Figure(dpi=dpi, facecolor='none', edgecolor='none')
fig.set_alpha(0)
fig.set_figheight(height/dpi)
fig.set_figwidth(width/dpi)
ax = fig.add_axes([0., 0., 1., 1.], xticks=[], yticks=[])
ax.set_axis_off()
if request.GET['logscale'] is True:
norm_func = mpl.colors.LogNorm
else:
norm_func = mpl.colors.Normalize
# Set out of bound data to NaN so it shows transparent?
# Set to black like ncWMS?
# Configurable by user?
if cmin is not None and cmax is not None:
lvls = np.linspace(cmin, cmax, nlvls)
norm = norm_func(vmin=cmin, vmax=cmax, clip=True)
else:
lvls = nlvls
norm = norm_func()
if request.GET['image_type'] == 'filledcontours':
ax.tricontourf(tri_subset, data, lvls, norm=norm, cmap=colormap, extend='both')
elif request.GET['image_type'] == 'contours':
ax.tricontour(tri_subset, data, lvls, norm=norm, cmap=colormap, extend='both')
ax.set_xlim(bbox.minx, bbox.maxx)
ax.set_ylim(bbox.miny, bbox.maxy)
ax.set_frame_on(False)
ax.set_clip_on(False)
ax.set_position([0., 0., 1., 1.])
canvas = FigureCanvasAgg(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例4: reports_pie
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [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
示例5: save_plot
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def save_plot(fname, plot_name, plot):
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter
fig = Figure()
ax = fig.add_subplot(111)
ax.xaxis.set_major_formatter(DateFormatter('%H:%M'))
ax.set_xlabel("Time")
ax.set_ylabel(plot_name)
fig.set_figheight(20)
fig.set_figwidth(30)
fig.autofmt_xdate()
handles = []
labels = []
for graph in plot:
x, y = plot[graph]
handles.append(ax.plot(x, y))
labels.append(graph)
fig.legend(handles, labels, 1, shadow=True)
canvas = FigureCanvas(fig)
canvas.print_figure(fname, dpi=80)
示例6: quiver_response
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def quiver_response(lon,
lat,
dx,
dy,
request,
vectorscale,
unit_vectors=False,
dpi=80):
bbox = request.GET['bbox']
width = request.GET['width']
height = request.GET['height']
colormap = request.GET['colormap']
colorscalerange = request.GET['colorscalerange']
cmin = colorscalerange.min
cmax = colorscalerange.max
crs = request.GET['crs']
EPSG4326 = pyproj.Proj(init='EPSG:4326')
x, y = pyproj.transform(EPSG4326, crs, lon, lat) # TODO order for non-inverse?
fig = Figure(dpi=dpi, facecolor='none', edgecolor='none')
fig.set_alpha(0)
fig.set_figheight(height/dpi)
fig.set_figwidth(width/dpi)
ax = fig.add_axes([0., 0., 1., 1.], xticks=[], yticks=[])
ax.set_axis_off()
mags = np.sqrt(dx**2 + dy**2)
cmap = mpl.cm.get_cmap(colormap)
# Set out of bound data to NaN so it shows transparent?
# Set to black like ncWMS?
# Configurable by user?
norm = None
if cmin is not None and cmax is not None:
mags[mags > cmax] = cmax
mags[mags < cmin] = cmin
bounds = np.linspace(cmin, cmax, 15)
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
# plot unit vectors
if unit_vectors:
ax.quiver(x, y, dx/mags, dy/mags, mags, cmap=cmap, scale=vectorscale)
else:
ax.quiver(x, y, dx, dy, mags, cmap=cmap, norm=norm, scale=vectorscale)
ax.set_xlim(bbox.minx, bbox.maxx)
ax.set_ylim(bbox.miny, bbox.maxy)
ax.set_frame_on(False)
ax.set_clip_on(False)
ax.set_position([0., 0., 1., 1.])
canvas = FigureCanvasAgg(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例7: contouring_response
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def contouring_response(lon, lat, data, request, dpi=None):
dpi = dpi or 80.
bbox, width, height, colormap, cmin, cmax, crs = _get_common_params(request)
nlvls = request.GET['numcontours']
EPSG4326 = pyproj.Proj(init='EPSG:4326')
x, y = pyproj.transform(EPSG4326, crs, lon, lat)
fig = Figure(dpi=dpi, facecolor='none', edgecolor='none')
fig.set_alpha(0)
fig.set_figheight(height/dpi)
fig.set_figwidth(width/dpi)
ax = fig.add_axes([0., 0., 1., 1.], xticks=[], yticks=[])
ax.set_axis_off()
if request.GET['logscale'] is True:
norm_func = mpl.colors.LogNorm
else:
norm_func = mpl.colors.Normalize
if cmin is not None and cmax is not None:
data[data > cmax] = cmax
data[data < cmin] = cmin
lvls = np.linspace(cmin, cmax, nlvls)
norm = norm_func(vmin=cmin, vmax=cmax)
else:
lvls = nlvls
norm = norm_func()
if request.GET['image_type'] == 'filledcontours':
ax.contourf(x, y, data, lvls, norm=norm, cmap=colormap)
elif request.GET['image_type'] == 'contours':
ax.contour(x, y, data, lvls, norm=norm, cmap=colormap)
elif request.GET['image_type'] == 'filledhatches':
hatches = DEFAULT_HATCHES[:lvls]
ax.contourf(x, y, data, lvls, norm=norm, cmap=colormap, hatches=hatches)
elif request.GET['image_type'] == 'hatches':
hatches = DEFAULT_HATCHES[:lvls]
ax.contourf(x, y, data, lvls, norm=norm, colors='none', hatches=hatches)
ax.set_xlim(bbox.minx, bbox.maxx)
ax.set_ylim(bbox.miny, bbox.maxy)
ax.set_frame_on(False)
ax.set_clip_on(False)
ax.set_position([0., 0., 1., 1.])
canvas = FigureCanvasAgg(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例8: tricontourf_response
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def tricontourf_response(tri_subset,
data,
request,
dpi=80.0,
nlvls=15):
"""
triang_subset is a matplotlib.Tri object in lat/lon units (will be converted to projected coordinates)
xmin, ymin, xmax, ymax is the bounding pox of the plot in PROJETED COORDINATES!!!
request is the original getMap request object
"""
bbox = request.GET['bbox']
width = request.GET['width']
height = request.GET['height']
colormap = request.GET['colormap']
colorscalerange = request.GET['colorscalerange']
cmin = colorscalerange.min
cmax = colorscalerange.max
crs = request.GET['crs']
EPSG4326 = pyproj.Proj(init='EPSG:4326')
tri_subset.x, tri_subset.y = pyproj.transform(EPSG4326, crs, tri_subset.x, tri_subset.y)
fig = Figure(dpi=dpi, facecolor='none', edgecolor='none')
fig.set_alpha(0)
fig.set_figheight(height/dpi)
fig.set_figwidth(width/dpi)
ax = fig.add_axes([0., 0., 1., 1.], xticks=[], yticks=[])
ax.set_axis_off()
# Set out of bound data to NaN so it shows transparent?
# Set to black like ncWMS?
# Configurable by user?
if cmin and cmax:
data[data > cmax] = cmax
data[data < cmin] = cmin
lvls = np.linspace(float(cmin), float(cmax), int(nlvls))
ax.tricontourf(tri_subset, data, levels=lvls, cmap=colormap)
else:
ax.tricontourf(tri_subset, data, cmap=colormap)
ax.set_xlim(bbox.minx, bbox.maxx)
ax.set_ylim(bbox.miny, bbox.maxy)
ax.set_frame_on(False)
ax.set_clip_on(False)
ax.set_position([0., 0., 1., 1.])
canvas = FigureCanvasAgg(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例9: contourf_response
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def contourf_response(lon,
lat,
data,
request,
dpi=80,
nlvls = 15):
xmin, ymin, xmax, ymax = wms_handler.get_bbox(request)
width, height = wms_handler.get_width_height(request)
colormap = wms_handler.get_colormap(request)
cmin, cmax = wms_handler.get_climits(request)
#proj = get_pyproj(request)
#xcrs, ycrs = proj(lon.flatten(),lat.flatten())
CRS = get_pyproj(request)
xcrs, ycrs = pyproj.transform(EPSG4326, CRS, lon.flatten(),lat.flatten()) #TODO order for non-inverse?
#logger.info("xcrs, ycrs: {0} {1}".format(xcrs, ycrs))
xcrs = xcrs.reshape(data.shape)
ycrs = ycrs.reshape(data.shape)
sxcrs = np.argsort(xcrs[1,:])
sycrs = np.argsort(ycrs[:,1])
fig = Figure(dpi=dpi, facecolor='none', edgecolor='none')
fig.set_alpha(0)
fig.set_figheight(height/dpi)
fig.set_figwidth(width/dpi)
ax = fig.add_axes([0., 0., 1., 1.], xticks=[], yticks=[])
lvls = np.linspace(cmin, cmax, nlvls)
#ax.contourf(xcrs, ycrs, data, levels=lvls, cmap=colormap)
ax.contourf(xcrs[sycrs,:][:,sxcrs], ycrs[sycrs,:][:,sxcrs], data[sycrs,:][:,sxcrs], levels=lvls, cmap=colormap)
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
ax.set_frame_on(False)
ax.set_clip_on(False)
ax.set_position([0, 0, 1, 1])
canvas = FigureCanvasAgg(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例10: create_projected_fig
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def create_projected_fig(lonmin, latmin, lonmax, latmax, projection, height, width):
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
fig = Figure(dpi=80, facecolor='none', edgecolor='none')
fig.set_alpha(0)
fig.set_figheight(height)
fig.set_figwidth(width)
m = Basemap(llcrnrlon=lonmin, llcrnrlat=latmin,
urcrnrlon=lonmax, urcrnrlat=latmax, projection=projection,
resolution=None,
lat_ts = 0.0,
suppress_ticks=True)
m.ax = fig.add_axes([0, 0, 1, 1], xticks=[], yticks=[])
return fig, m
示例11: blank_canvas
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def blank_canvas(width, height, dpi=5):
"""
return a transparent (blank) response
used for tiles with no intersection with the current view or for some other error.
"""
fig = Figure(dpi=dpi, facecolor='none', edgecolor='none')
fig.set_alpha(0)
ax = fig.add_axes([0, 0, 1, 1])
fig.set_figheight(height/dpi)
fig.set_figwidth(width/dpi)
ax.set_frame_on(False)
ax.set_clip_on(False)
ax.set_position([0, 0, 1, 1])
canvas = FigureCanvasAgg(fig)
return canvas
示例12: general_graph
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def general_graph(polarity,name):
# Create a figure and a canvas to draw in
fig = Figure()
fig.set_figwidth(12)
canvas = FigureCanvas(fig)
# Set the legend and the colors for the plot
legend=["P+", "P", "NEU", "N", "N+", "NONE"]
colors=["#A7DB40","#D8E067","#FFB81F","#FF743D","#C4213D","#707070"]
# Set the figure configuration and parameters
ax = fig.add_subplot(1,1,1, axisbg='white')
ax.set_ylabel('Polarity value')
ax.set_xlabel('Date')
ax.set_title('Polarity evolution for the query: '+ name)
# Set the x axis indices for every plotting
N = len(polarity[6])
ind = np.arange(N)# creates an numpy.array from 0 to N-1
# This is used in order to skip the dates where there is no information
def format_date(x, pos=None):
thisind = np.clip(int(x+0.5), 0, N-1)
return polarity[6][thisind].strftime('%h,%d %Hh.')
ax.autoscale(tight=True)
ax.grid(True)
i=0
# Plot all the polarity evolution lines
while i < 6:
ax.plot(ind,polarity[i],colors[i],label=legend[i],linewidth=3)
i+=1
# Plot the legend in the graphic
ax.legend()
# As indices are being used instead of dates, each index has to be
# asociated with the correspondig date using the funcion defined
# above
ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
fig.autofmt_xdate()
#Save the graphic as an image
canvas.print_figure('tweetclass/static/tweetclass/histogram_generic_'+name+'.png',facecolor="#EBE8E9",bbox_inches='tight')
示例13: _draw_figure
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def _draw_figure(self, title, filename, x_values, y_values, x_label, y_label):
figure = Figure()
canvas = FigureCanvas(figure)
axes = figure.add_axes([0.15, 0.1, 0.7, 0.7])
axes.plot(x_values, y_values)
axes.grid(True)
axes.set_xlabel(x_label)
axes.set_ylabel(y_label)
axes.set_title(title)
figure.set_figheight(8)
figure.set_figwidth(15)
try:
figure.savefig(filename)
#canvas.print_png(filename)
except Exception, e:
logger.error(title)
logger.error(filename)
logger.error(str(e))
示例14: radial_summary
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def radial_summary(values,name):
# Set the colors for the plot
colors=["#A7DB40","#D8E067","#FFB81F","#FF743D","#C4213D","#707070"]
# Create a figure and a canvas to draw in
fig = Figure()
canvas = FigureCanvas(fig)
fig.set_figwidth(1)
fig.set_figheight(1)
# Set the figure configuration and parameters
ax = fig.add_subplot(1,1,1)
# Plot the pie with the diferent values and colors
ax.pie(values,colors=colors, shadow=True, startangle=90)
#Save the graphic as an image
canvas.print_figure('tweetclass/static/tweetclass/summary_pie_'+name+'.png',bbox_inches='tight')
示例15: getImage
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import set_figwidth [as 别名]
def getImage(self):
figure = Figure()
axes = figure.add_subplot(111)
axes.plot(self.signal_read())
canvas = FigureCanvas(figure)
figure.set_figwidth(6)
figure.set_figheight(2)
figure.savefig(self.fileImage)
fig = QLabel()
fig.setPixmap(QPixmap(self.fileImage))
fig.setFixedSize(600, 200)
return fig