本文整理匯總了Python中matplotlib.pyplot.plot_date方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.plot_date方法的具體用法?Python pyplot.plot_date怎麽用?Python pyplot.plot_date使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.plot_date方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: comparisonPlot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def comparisonPlot(year,month,day,seriesList,nameList,plotName="Comparison of Values over Time", yAxisName="Predicted"):
date = datetime.date(year,month,day)
dateList = []
for x in range(len(seriesList[0])):
dateList.append(date+datetime.timedelta(days=x))
colors = ["b","g","r","c","m","y","k","w"]
currColor = 0
legendVars = []
for i in range(len(seriesList)):
x, = plt.plot_date(x=dateList,y=seriesList[i],color=colors[currColor],linestyle="-",marker=".")
legendVars.append(x)
currColor += 1
if (currColor >= len(colors)):
currColor = 0
plt.legend(legendVars, nameList)
plt.title(plotName)
plt.ylabel(yAxisName)
plt.xlabel("Date")
plt.show()
示例2: toImage
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def toImage(self):
from StringIO import StringIO
import matplotlib.pyplot as plt
from matplotlib.dates import date2num
times = [date2num(datetime.fromtimestamp(dayavglistdict[0]['time'], pytz.utc).date()) for dayavglistdict in
self.results()]
means = [dayavglistdict[0]['mean'] for dayavglistdict in self.results()]
plt.plot_date(times, means, '|g-')
plt.xlabel('Date')
plt.xticks(rotation=70)
plt.ylabel(u'Difference from 5-Day mean (\u00B0C)')
plt.title('Sea Surface Temperature (SST) Anomalies')
plt.grid(True)
plt.tight_layout()
sio = StringIO()
plt.savefig(sio, format='png')
return sio.getvalue()
示例3: graph_mag_time
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def graph_mag_time(catalog, prefix):
"""Plot magnitudes vs. origin time."""
catalog = catalog[pd.notnull(catalog['mag'])]
times = catalog['convtime'].copy()
mags = catalog['mag'].copy()
plt.figure(figsize=(10, 6))
plt.xlabel('Date', fontsize=14)
plt.ylabel('Magnitude', fontsize=14)
plt.plot_date(times, mags, alpha=0.7, markersize=2, c='b')
plt.xlim(min(times), max(times))
plt.title('Magnitude vs. Time', fontsize=20)
plt.savefig('%s_magvtime.png' % prefix, dpi=300)
plt.close()
示例4: graph_event_types
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def graph_event_types(catalog, prefix):
"""Graph number of cumulative events by type of event."""
typedict = {}
for evtype in catalog['type'].unique():
typedict[evtype] = (catalog['type'] == evtype).cumsum()
plt.figure(figsize=(12, 6))
for evtype in typedict:
plt.plot_date(catalog['convtime'], typedict[evtype], marker=None,
linestyle='-', label=evtype)
plt.yscale('log')
plt.legend()
plt.xlim(min(catalog['convtime']), max(catalog['convtime']))
plt.xlabel('Date', fontsize=14)
plt.ylabel('Cumulative number of events', fontsize=14)
plt.title('Cumulative Event Type', fontsize=20)
plt.savefig('%s_cumuleventtypes.png' % prefix, dpi=300)
plt.close()
示例5: plot_date
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def plot_date(dataframe, column_name):
"""
:param dataframe:
:param column_name:
:type column_name:str
:return:
"""
fig = plt.figure(figsize=(11.69, 8.27))
p = plt.plot(dataframe.index, dataframe[column_name], 'b-', label=r"%s" % column_name)
plt.hlines(0, min(dataframe.index), max(dataframe.index), 'r')
plt.legend(loc='best')
fig.autofmt_xdate(rotation=90)
return p
示例6: test_single_date
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def test_single_date():
time1 = [721964.0]
data1 = [-65.54]
fig = plt.figure()
plt.subplot(211)
plt.plot_date(time1, data1, 'o', color='r')
plt.subplot(212)
plt.plot(time1, data1, 'o', color='r')
示例7: make_efficiency_date
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def make_efficiency_date(
total_data,
avg_data,
f_name,
title=None,
x_label=None,
y_label=None,
x_ticks=None,
y_ticks=None,
):
fig = plt.figure()
if title is not None:
plt.title(title, fontsize=16)
if x_label is not None:
plt.ylabel(x_label)
if y_label is not None:
plt.xlabel(y_label)
v_date = []
v_val = []
for data in total_data:
dates = dt.date2num(datetime.datetime.strptime(data[0], "%H:%M"))
to_int = round(float(data[1]))
plt.plot_date(dates, data[1], color=plt.cm.brg(to_int))
for data in avg_data:
dates = dt.date2num(datetime.datetime.strptime(data[0], "%H:%M"))
v_date.append(dates)
v_val.append(data[1])
plt.plot_date(v_date, v_val, "^y-", label="Average")
plt.legend()
plt.savefig(f_name)
plt.close(fig)
示例8: plotBrokerQueue
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def plotBrokerQueue(dataTask, filename):
"""Generates the broker queue length graphic."""
print("Plotting broker queue length for {0}.".format(filename))
plt.figure()
# Queue length
plt.subplot(211)
for fichier, vals in dataTask.items():
if type(vals) == list:
timestamps = list(map(datetime.fromtimestamp, map(int, list(zip(*vals))[0])))
# Data is from broker
plt.plot_date(timestamps, list(zip(*vals))[2],
linewidth=1.0,
marker='o',
markersize=2,
label=fichier)
plt.title('Broker queue length')
plt.ylabel('Tasks')
# Requests received
plt.subplot(212)
for fichier, vals in dataTask.items():
if type(vals) == list:
timestamps = list(map(datetime.fromtimestamp, map(int, list(zip(*vals))[0])))
# Data is from broker
plt.plot_date(timestamps, list(zip(*vals))[3],
linewidth=1.0,
marker='o',
markersize=2,
label=fichier)
plt.title('Broker pending requests')
plt.xlabel('time (s)')
plt.ylabel('Requests')
plt.savefig(filename)
示例9: test_date_timezone_x
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def test_date_timezone_x():
# Tests issue 5575
time_index = [datetime.datetime(2016, 2, 22, hour=x,
tzinfo=dutz.gettz('Canada/Eastern'))
for x in range(3)]
# Same Timezone
fig = plt.figure(figsize=(20, 12))
plt.subplot(2, 1, 1)
plt.plot_date(time_index, [3] * 3, tz='Canada/Eastern')
# Different Timezone
plt.subplot(2, 1, 2)
plt.plot_date(time_index, [3] * 3, tz='UTC')
示例10: test_date_timezone_y
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def test_date_timezone_y():
# Tests issue 5575
time_index = [datetime.datetime(2016, 2, 22, hour=x,
tzinfo=dutz.gettz('Canada/Eastern'))
for x in range(3)]
# Same Timezone
fig = plt.figure(figsize=(20, 12))
plt.subplot(2, 1, 1)
plt.plot_date([3] * 3,
time_index, tz='Canada/Eastern', xdate=False, ydate=True)
# Different Timezone
plt.subplot(2, 1, 2)
plt.plot_date([3] * 3, time_index, tz='UTC', xdate=False, ydate=True)
示例11: test_date_timezone_x_and_y
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def test_date_timezone_x_and_y():
# Tests issue 5575
UTC = datetime.timezone.utc
time_index = [datetime.datetime(2016, 2, 22, hour=x, tzinfo=UTC)
for x in range(3)]
# Same Timezone
fig = plt.figure(figsize=(20, 12))
plt.subplot(2, 1, 1)
plt.plot_date(time_index, time_index, tz='UTC', ydate=True)
# Different Timezone
plt.subplot(2, 1, 2)
plt.plot_date(time_index, time_index, tz='US/Eastern', ydate=True)
示例12: plot_on_timeline
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def plot_on_timeline(col, verbose=True):
"""Plots points on a timeline
Parameters
----------
col : np.array
verbose : boolean
iff True, display the graph
Returns
-------
matplotlib.figure.Figure
Figure containing plot
Returns
-------
matplotlib.figure.Figure
"""
col = utils.check_col(col)
# http://stackoverflow.com/questions/1574088/plotting-time-in-python-with-matplotlib
if is_nd(col):
col = col.astype(datetime)
dates = matplotlib.dates.date2num(col)
fig = plt.figure()
plt.plot_date(dates, [0] * len(dates))
if verbose:
plt.show()
return fig
示例13: plot_city_data
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def plot_city_data(*city_data_dicts):
cities = []
for city_data in city_data_dicts:
cities.append(city_data['name'])
plt.plot_date(city_data['date'], city_data['temperature'], '.')
plt.ylabel('Temperature (C)')
plt.xlabel('Date')
plt.ylim([0, 110])
plt.legend(cities)
plt.show()
示例14: yearlyPlot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def yearlyPlot(ySeries,year,month,day,plotName ="Plot",yAxisName="yData"):
date = datetime.date(year,month,day)
dateList = []
for x in range(len(ySeries)):
dateList.append(date+datetime.timedelta(days=x))
plt.plot_date(x=dateList,y=ySeries,fmt="r-")
plt.title(plotName)
plt.ylabel(yAxisName)
plt.xlabel("Date")
plt.grid(True)
plt.show()
# Plots autocorrelation factors against varying time lags for ySeries
示例15: graph
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import plot_date [as 別名]
def graph(models):
for model in models:
print("Loading pre-trained model...")
sess = tf.Session()
saver = tf.train.import_meta_graph("data/model/"+str(model)+'/'+str(model)+'.ckpt.meta')
saver.restore(sess, tf.train.latest_checkpoint('data/model/'+str(model)))
print("Model loaded...")
graph = tf.get_default_graph()
if model == 'feedforward':
x = graph.get_tensor_by_name('input:0')
prediction = graph.get_tensor_by_name('output:0')
elif model == 'recurrent':
x = graph.get_tensor_by_name('input_recurrent:0')
prediction = graph.get_tensor_by_name('output_recurrent:0')
_, _, _, _, oil_price, stock_price = dp.create_data()
predictions = []
if model == 'feedforward':
date_labels = oil_price.index
date_labels = matplotlib.dates.date2num(date_labels.to_pydatetime())
for i in oil_price:
predictions.append(sess.run(prediction, feed_dict={x: [[i]]})[0][0])
elif model == 'recurrent':
predictions = []
for index in range(int(len(oil_price.values) / total_chunk_size)):
x_in = oil_price.values[index * total_chunk_size:index * total_chunk_size + total_chunk_size].reshape(
(1, n_chunks, chunk_size))
predictions += sess.run(prediction, feed_dict={x: x_in})[0].reshape(total_chunk_size).tolist()
plt.plot_date(date_labels, predictions, 'b-', label="Feedforward Predictions")
plt.plot_date(date_labels, stock_price.values, 'r-', label='Stock Prices')
plt.legend()
plt.ylabel('Price')
plt.xlabel('Year')
plt.show()