本文整理汇总了Python中matplotlib.figure.Figure.autofmt_xdate方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.autofmt_xdate方法的具体用法?Python Figure.autofmt_xdate怎么用?Python Figure.autofmt_xdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.autofmt_xdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_loads_devs
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def plot_loads_devs(response, start, alldata, allmeans, meandates, maxload, notesets):
fig = Figure(figsize=(12,8), dpi=72)
rect = fig.patch
rect.set_facecolor('white')
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
colorlist = ['b', 'g', 'r', 'y', 'c']
plts = []
labels = []
colorlist_count = 0
for dev in alldata.keys():
labels.append(dev)
plt = ax.plot(alldata[dev]['dates'], alldata[dev]['loads'], colorlist[colorlist_count] + 'x')[0]
plts.append(plt)
colorlist_count += 1
ax.plot(meandates, allmeans, 'ks')
for i in range(len(meandates)):
outstr = "%.03f ug/cm^2\n" % (allmeans[i])
for j in notesets[i]:
outstr += j + "\n"
ax.text(meandates[i], allmeans[i], outstr)
ax.set_ylabel('$ug/cm^2$')
ax.set_xlabel('Image Record Time (from EXIF)')
ax.set_title("%s" % (str(start)))
fig.autofmt_xdate()
ax.legend(plts, labels, numpoints=1, loc='lower right')
fig.subplots_adjust(left=0.07, bottom=0.10, right=0.91, \
top=0.95, wspace=0.20, hspace=0.00)
canvas.print_png(response)
示例2: simple
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def simple(request):
import random
import django
import datetime
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter
print "hello"
#print form['subject'].value()
fig=Figure()
ax=fig.add_subplot(111)
x=[]
y=[]
now=datetime.datetime.now()
delta=datetime.timedelta(days=1)
for i in range(10):
x.append(now)
now+=delta
y.append(random.randint(0, 1000))
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas=FigureCanvas(fig)
response=django.http.HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例3: graph_prices
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def graph_prices(x, y, gname):
'''make a plot of the prices over time for a specific game'
x is be the dates of the bins
y is the prices
gname is the name of the game
'''
x_list = list(x)
x_dt = [datetime.fromtimestamp(xx) for xx in x_list]
fig=Figure(facecolor='white')
ax=fig.add_subplot(111)
ax.plot(x_dt,y,'r-')
ax.set_ylim([0,np.max(y) + np.max(y) * 0.10])
#ax.set_title(gname)
#ax.set_axis_bgcolor('red')
formatter = FuncFormatter(money_format)
ax.yaxis.set_major_formatter(formatter)
#fig.autofmt_xdate()
#xfmt = md.DateFormatter('%Y-%m-%d %H:%M:%S')
#ax.xaxis.set_major_formatter(xfmt)
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas=FigureCanvas(fig)
png_output = StringIO.StringIO()
canvas.print_png(png_output)
response=make_response(png_output.getvalue())
response.headers['Content-Type'] = 'image/png'
return response
示例4: konto_graph
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def konto_graph(request, year, konto_id):
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter
# Collect data
konto = Konto.objects.get(pk = konto_id)
innslags = konto.innslag.order_by('bilag__dato').filter(bilag__dato__year = year)
# make plot
fig=Figure()
fig.suptitle(u"%s (År:%s)"% (konto, unicode(year)))
ax=fig.add_subplot(111)
x=[]
y=[]
sum = Decimal(0)
for innslag in innslags:
x.append(innslag.bilag.dato)
y.append(sum)
x.append(innslag.bilag.dato)
sum += innslag.value
y.append(sum)
ax.plot_date(x, y, '-')
if x: # if there is transactions on the konto in the period
# fill the period from the end of the year with a red line
ax.plot_date([x[-1],date(int(year),12,31)],[y[-1],y[-1]],"r")
if x[0].day != 1 or x[0].month != 1:
ax.plot_date([date(int(year),1,1),x[0]],[0,0],"r")
else:
ax.plot_date([date(int(year),1,1),date(int(year),12,31)],[0,0],"r")
ax.xaxis.set_major_formatter(DateFormatter('%b'))
fig.autofmt_xdate()
canvas = FigureCanvas(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例5: startup_cost
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def startup_cost():
import datetime
import StringIO
import random
import base64
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter
fig=Figure(facecolor='#ffffff')
ax=fig.add_subplot(211)
ax2=fig.add_subplot(212, axisbg='y')
x=[]
y=[]
now=datetime.datetime.now()
delta=datetime.timedelta(days=1)
for i in range(10):
x.append(now)
now+=delta
y.append(random.randint(0, 1000))
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
ax2.plot_date(x, y, '-')
ax2.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas=FigureCanvas(fig)
png_output = StringIO.StringIO()
canvas.print_png(png_output)
image=make_response(png_output.getvalue())
response.headers['Content-Type'] = 'image/png'
return response
示例6: simple
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def simple(request):
import random
import django
import datetime
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter
fig = Figure(figsize=(5, 5), dpi=80)
ax = fig.add_subplot(111)
x = []
y = []
now = datetime.datetime.now()
delta = datetime.timedelta(days=1)
for i in range(10):
x.append(now)
now += delta
y.append(random.randint(0, 1000))
ax.plot_date(x, y, "-")
ax.xaxis.set_major_formatter(DateFormatter("%Y-%m-%d"))
fig.autofmt_xdate()
canvas = FigureCanvas(fig)
response = django.http.HttpResponse(content_type="image/png")
canvas.print_png(response)
return response
示例7: show_temperature_graph
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def show_temperature_graph(response, siteLocation=None):
import random
import os
import tempfile
os.environ['MPLCONFIGDIR'] = tempfile.mkdtemp()
import django
import datetime
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)
x=[]
y=[]
now=datetime.datetime.now()
delta=datetime.timedelta(days=1)
for i in range(10):
x.append(now)
now+=delta
y.append(random.randint(0, 1000))
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas=FigureCanvas(fig)
response=django.http.HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例8: simple
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def simple(request):
simpleimgdata = StringIO.StringIO()
simpleimgdata.buf=""
fig=Figure()
ax=fig.add_subplot(111)
x=[]
y=[]
now=datetime.datetime.now()
delta=datetime.timedelta(days=1)
for i in range(10):
x.append(now)
now+=delta
y.append(random.randint(0, 1000))
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
plt.savefig(simpleimgdata, format='png')
simpleimgdata.seek(0)
uri = 'data:image/png;base64,' + urllib.quote(base64.b64encode(simpleimgdata.buf))
# element= '<img src = "%s"/>' % uri
simpleimgdata.truncate()
simpleimgdata.seek(0)
simpleimgdata.close()
response = HttpResponse()
response.write(uri)
return response
示例9: plot_supply
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def plot_supply(request):
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter
currency = request.GET['currency']
genesis = crypto_data[currency.lower()]['genesis_date']
currency_name = crypto_data[currency.lower()]['name']
s = SupplyEstimator(currency)
try:
max_block = crypto_data[currency.lower()]['supply_data']['reward_ends_at_block']
end = s.estimate_date_from_height(max_block)
except KeyError:
end = genesis + datetime.timedelta(days=365 * 50)
x = list(date_generator(genesis, end))
y = [s.calculate_supply(at_time=z)/1e6 for z in x]
fig = Figure()
ax = fig.add_subplot(111)
ax.plot_date(x, y, '-')
ax.set_title("%s Supply" % currency_name)
ax.grid(True)
ax.xaxis.set_label_text("Date")
ax.yaxis.set_label_text("%s Units (In millions)" % currency.upper())
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas = FigureCanvas(fig)
response = http.HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例10: drawPlot
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def drawPlot(property, unit, interval):
if unit in ("hours", "minutes"):
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter, HourLocator, MinuteLocator, SecondLocator
from io import BytesIO
last = (
db.session.query(Measurement)
.filter(Measurement.property == property)
.order_by(Measurement.id.desc())
.first()
)
if not last:
return abort(404)
# Get measurement data
if unit == "hours":
ms = Measurement.query.filter(
Measurement.property == property, Measurement.time > last.time - datetime.timedelta(hours=int(interval))
).all()
elif unit == "minutes":
ms = Measurement.query.filter(
Measurement.property == property,
Measurement.time > last.time - datetime.timedelta(minutes=int(interval)),
).all()
t = []
T = []
# organize.. could this be done smarter?
for m in ms:
t.append(m.time)
T.append(m.value)
# Make plot
fig = Figure()
ax = fig.add_subplot(111)
ax.plot_date(t, T, "-")
if unit == "hours":
ax.xaxis.set_major_locator(MinuteLocator(interval=10 * int(interval)))
ax.xaxis.set_minor_locator(MinuteLocator(interval=int(interval)))
elif unit == "minutes":
ax.xaxis.set_major_locator(SecondLocator(interval=10 * int(interval)))
ax.xaxis.set_minor_locator(SecondLocator(interval=int(interval)))
ax.xaxis.set_major_formatter(DateFormatter("%h %d, %H:%M"))
x1, x2, y1, y2 = ax.axis()
ax.axis((x1, x2, y1 - 1, y2 + 1))
fig.autofmt_xdate()
# Return plot
canvas = FigureCanvas(fig)
png_output = BytesIO()
canvas.print_png(png_output)
response = make_response(png_output.getvalue())
response.headers["Content-Type"] = "image/png"
return response
示例11: simple
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def simple():
import datetime
import random
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)
x = []
y = []
now = datetime.datetime.now()
delta = datetime.timedelta(days=1)
for i in range(10):
x.append(now)
now += delta
y.append(random.randint(0, 1000))
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas = FigureCanvas(fig)
data, shape = canvas.print_to_buffer()
y, x = shape
array = frombuffer(data, dtype=uint8, count=x*y*4)
return array.reshape((x, y, 4))
示例12: tiled_axis
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def tiled_axis( ts, filename=None ):
fig = Figure( ( 2.56 * 4, 2.56 * 4), 300 )
canvas = FigureCanvas(fig)
#ax = fig.add_subplot(111)
grid = ImageGrid(fig, 111, # similar to subplot(111)
nrows_ncols = (3, 1),
axes_pad = 0.5,
add_all=True,
label_mode = "L",
)
# pad half a day so that major ticks show up in the middle, not on the edges
delta = dates.relativedelta( days=2, hours=12 )
# XXX: gets a list of days.
timestamps = glucose.get_days( ts.time )
xmin, xmax = ( timestamps[ 0 ] - delta,
timestamps[ -1 ] + delta )
fig.autofmt_xdate( )
def make_plot( ax, limit ):
preferspan = ax.axhspan( SAFE[0], SAFE[1],
facecolor='g', alpha=0.2,
edgecolor = '#003333',
linewidth=1
)
def draw_title( ax, limit ):
ax.set_title('glucose history')
#ax.set_ylabel('glucose mm/dL')
return canvas
示例13: img
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def img(request):
import random
import matplotlib as mpl
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter
mpl.rcParams['timezone'] = 'Asia/Seoul'
latest_data = HumidTemp.objects.all().order_by('-id')[:1440]
fig = Figure()
ax=fig.add_subplot(211)
x=[]
y=[]
tempy=[]
for data in latest_data:
x.append(data.collect_datetime)
y.append(data.humidity)
tempy.append(data.temperature)
# ax.plot_date(x, y, '-')
#ax.xaxis.set_major_formatter(DateFormatter('%m-%d %H:%M'))
ax.plot(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%m-%d %H:%M'))
ax2 = fig.add_subplot(212)
ax2.plot(x, tempy, '-')
ax2.xaxis.set_major_formatter(DateFormatter('%m-%d %H:%M'))
fig.autofmt_xdate()
canvas=FigureCanvas(fig)
response= HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
示例14: plot_grads
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
def plot_grads(response, start, thedate, thedata, sampled):
fig = Figure(figsize=(12,8), dpi=72)
rect = fig.patch
rect.set_facecolor('white')
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
pout = ax.plot(thedate, sampled, 'ok')
pout = ax.plot(
thedate, thedata[0], 'bx',
thedate, thedata[1], 'gx',
thedate, thedata[2], 'rx',
thedate, thedata[3], 'cx',
thedate, thedata[4], 'mx',
thedate, thedata[5], 'yx',
thedate, thedata[6], 'kx',
thedate, thedata[7], 'bx',
thedate, thedata[8], 'gx',
thedate, thedata[9], 'rx',
thedate, thedata[10], 'cx',
thedate, thedata[11], 'mx'
)
fig.autofmt_xdate()
ax.fmt_xdata = mdates.DateFormatter('%Y-%m-%d %H:%M')
ax.set_ylim(0,300)
ax.set_title(start.strftime("%Y-%m-%d %H:%M:%S"))
canvas.print_png(response)
示例15: ChartCanvas
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import autofmt_xdate [as 别名]
class ChartCanvas():
"""
Container for the matplotlib (or any other) chart object
"""
def __init__(self, container, config):
# Create the matplotlib figure and attach it to a canvas
self.figure = Figure(
(config.chart_width, config.chart_height),
dpi=config.chart_dpi)
self.canvas = FigureCanvasWxAgg(container, -1, self.figure)
self.chart = self.figure.add_subplot(111)
def layout(self):
return self.canvas
def draw(self, data, _):
"""
Redraw figure
"""
logging.debug('Redrawing time series')
self.chart.clear()
# self.axes.grid(self.cb_grid.IsChecked())
self.chart.plot(data['dates'], data['values'])
self.figure.autofmt_xdate()
self.canvas.draw()