本文整理匯總了Python中matplotlib.pyplot.setp方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.setp方法的具體用法?Python pyplot.setp怎麽用?Python pyplot.setp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.setp方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: hover_over_bin
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def hover_over_bin(event, handle_tickers, handle_plots, colors, fig):
is_found = False
for iobj in range(len(handle_tickers)):
for ibin in range(len(handle_tickers[iobj])):
cont = False
if not is_found:
cont, ind = handle_tickers[iobj][ibin].contains(event)
if cont:
is_found = True
if cont:
plt.setp(handle_tickers[iobj][ibin], facecolor=colors[iobj])
[h.set_visible(True) for h in handle_plots[iobj][ibin]]
is_found = True
fig.canvas.draw_idle()
else:
plt.setp(handle_tickers[iobj][ibin], facecolor=(1, 1, 1))
for h in handle_plots[iobj][ibin]:
h.set_visible(False)
fig.canvas.draw_idle()
示例2: plot_attention
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def plot_attention(sentences, attentions, labels, **kwargs):
fig, ax = plt.subplots(**kwargs)
im = ax.imshow(attentions, interpolation='nearest',
vmin=attentions.min(), vmax=attentions.max())
plt.colorbar(im, shrink=0.5, ticks=[0, 1])
plt.setp(ax.get_xticklabels(), rotation=45, ha="right",
rotation_mode="anchor")
ax.set_yticks(range(len(labels)))
ax.set_yticklabels(labels, fontproperties=getChineseFont())
# Loop over data dimensions and create text annotations.
for i in range(attentions.shape[0]):
for j in range(attentions.shape[1]):
text = ax.text(j, i, sentences[i][j],
ha="center", va="center", color="b", size=10,
fontproperties=getChineseFont())
ax.set_title("Attention Visual")
fig.tight_layout()
plt.show()
示例3: render
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def render(self, current_step, net_worths, benchmarks, trades, window_size=50):
net_worth = round(net_worths[-1], 2)
initial_net_worth = round(net_worths[0], 2)
profit_percent = round((net_worth - initial_net_worth) / initial_net_worth * 100, 2)
self.fig.suptitle('Net worth: $' + str(net_worth) +
' | Profit: ' + str(profit_percent) + '%')
window_start = max(current_step - window_size, 0)
step_range = slice(window_start, current_step)
times = self.df.index.values[step_range]
self._render_net_worth(step_range, times, current_step, net_worths, benchmarks)
self._render_price(step_range, times, current_step)
self._render_volume(step_range, times)
self._render_trades(step_range, trades)
self.price_ax.set_xticklabels(times, rotation=45, horizontalalignment='right')
# Hide duplicate net worth date labels
plt.setp(self.net_worth_ax.get_xticklabels(), visible=False)
# Necessary to view frames before they are unrendered
plt.pause(0.001)
示例4: plotSigHeats
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def plotSigHeats(signals,markets,start=0,step=2,size=1,iters=6):
"""
打印信號回測盈損熱度圖,尋找參數穩定島
"""
sigMat = pd.DataFrame(index=range(iters),columns=range(iters))
for i in range(iters):
for j in range(iters):
climit = start + i*step
wlimit = start + j*step
caps,poss = plotSigCaps(signals,markets,climit=climit,wlimit=wlimit,size=size,op=False)
sigMat[i][j] = caps[-1]
sns.heatmap(sigMat.values.astype(np.float64),annot=True,fmt='.2f',annot_kws={"weight": "bold"})
xTicks = [i+0.5 for i in range(iters)]
yTicks = [iters-i-0.5 for i in range(iters)]
xyLabels = [str(start+i*step) for i in range(iters)]
_, labels = plt.yticks(yTicks,xyLabels)
plt.setp(labels, rotation=0)
_, labels = plt.xticks(xTicks,xyLabels)
plt.setp(labels, rotation=90)
plt.xlabel('Loss Stop @')
plt.ylabel('Profit Stop @')
return sigMat
示例5: draw_heatmap
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def draw_heatmap(array, input_seq, output_seq, dirname, name):
dirname = os.path.join('log', dirname)
if not os.path.exists(dirname):
os.makedirs(dirname)
fig, axes = plt.subplots(2, 4)
cnt = 0
for i in range(2):
for j in range(4):
axes[i, j].imshow(array[cnt].transpose(-1, -2))
axes[i, j].set_yticks(np.arange(len(input_seq)))
axes[i, j].set_xticks(np.arange(len(output_seq)))
axes[i, j].set_yticklabels(input_seq, fontsize=4)
axes[i, j].set_xticklabels(output_seq, fontsize=4)
axes[i, j].set_title('head_{}'.format(cnt), fontsize=10)
plt.setp(axes[i, j].get_xticklabels(), rotation=45, ha="right",
rotation_mode="anchor")
cnt += 1
fig.suptitle(name, fontsize=12)
plt.tight_layout()
plt.savefig(os.path.join(dirname, '{}.pdf'.format(name)))
plt.close()
示例6: _label_axis
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def _label_axis(ax, kind='x', label='', position='top',
ticks=True, rotate=False):
from matplotlib.artist import setp
if kind == 'x':
ax.set_xlabel(label, visible=True)
ax.xaxis.set_visible(True)
ax.xaxis.set_ticks_position(position)
ax.xaxis.set_label_position(position)
if rotate:
setp(ax.get_xticklabels(), rotation=90)
elif kind == 'y':
ax.yaxis.set_visible(True)
ax.set_ylabel(label, visible=True)
# ax.set_ylabel(a)
ax.yaxis.set_ticks_position(position)
ax.yaxis.set_label_position(position)
return
示例7: render
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def render(self, filename):
"""
Renders the attention graph over timesteps.
Args:
filename (string): filename to save the figure to.
"""
figure, axes = plt.subplots()
graph = np.stack(self.attentions)
axes.imshow(graph, cmap=plt.cm.Blues, interpolation="nearest")
axes.xaxis.tick_top()
axes.set_xticks(range(len(self.keys)))
axes.set_xticklabels(self.keys)
plt.setp(axes.get_xticklabels(), rotation=90)
axes.set_yticks(range(len(self.generated_values)))
axes.set_yticklabels(self.generated_values)
axes.set_aspect(1, adjustable='box')
plt.tick_params(axis='x', which='both', bottom='off', top='off')
plt.tick_params(axis='y', which='both', left='off', right='off')
figure.savefig(filename)
示例8: plotTimeShareChart
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def plotTimeShareChart(self, code, date, n):
date = self._daysEngine.codeTDayOffset(code, date, n)
if date is None: return
DyMatplotlib.newFig()
# plot stock time share chart
self._plotTimeShareChart(code, date, left=0.05, right=0.95, top=0.95, bottom=0.05)
# plot index time share chart
#self._plotTimeShareChart(self._daysEngine.getIndex(code), date, left=0.05, right=0.95, top=0.45, bottom=0.05)
# layout
f = plt.gcf()
plt.setp([a.get_xticklabels() for a in f.axes[::2]], visible=False)
f.show()
示例9: _plotAckRWExtremas
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def _plotAckRWExtremas(self, event):
code = event.data['code']
df = event.data['df']
regionalLocals = event.data['regionalLocals']
DyMatplotlib.newFig()
f = plt.gcf()
index = df.index
startDay = index[0].strftime('%Y-%m-%d')
endDay = index[-1].strftime('%Y-%m-%d')
# plot stock
periods = self._plotCandleStick(code, startDate=startDay, endDate=endDay, baseDate=endDay, left=0.05, right=0.95, top=0.95, bottom=0.5, maIndicator='close')
self._plotRegionalLocals(f.axes[0], index, regionalLocals)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
f.show()
示例10: _plotAckHSARs
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def _plotAckHSARs(self, event):
code = event.data['code']
df = event.data['df']
hsars = event.data['hsars']
DyMatplotlib.newFig()
f = plt.gcf()
index = df.index
startDay = index[0].strftime('%Y-%m-%d')
endDay = index[-1].strftime('%Y-%m-%d')
# plot stock
periods = self._plotCandleStick(code, startDate=startDay, endDate=endDay, baseDate=endDay, left=0.05, right=0.95, top=0.95, bottom=0.5, maIndicator='close')
self._plotHSARs(f.axes[0], hsars)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
f.show()
示例11: plotAckKama
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def plotAckKama(self, event):
code, startDate, endDate = '002551.SZ', '2015-07-01', '2016-03-01'
# load
if not self._daysEngine.load([-200, startDate, endDate], codes=[code]):
return
DyMatplotlib.newFig()
# plot basic stock K-Chart
periods = self._plotCandleStick(code, startDate=startDate, endDate=endDate, netCapitalFlow=True, left=0.05, right=0.95, top=0.95, bottom=0.5)
# plot customized stock K-Chart
self._plotKamaCandleStick(code, periods=periods, left=0.05, right=0.95, top=0.45, bottom=0.05)
# layout
f = plt.gcf()
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
f.show()
示例12: plotWeights
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def plotWeights(En, A, model):
import matplotlib.pyplot as plt
plt.figure(tight_layout=True)
plotInd = 511
for layer in model.layers:
try:
w_layer = layer.get_weights()[0]
ax = plt.subplot(plotInd)
newX = np.arange(En[0], En[-1], (En[-1]-En[0])/w_layer.shape[0])
plt.plot(En, np.interp(En, newX, w_layer[:,0]), label=layer.get_config()['name'])
plt.legend(loc='upper right')
plt.setp(ax.get_xticklabels(), visible=False)
plotInd +=1
except:
pass
ax1 = plt.subplot(plotInd)
ax1.plot(En, A[0], label='Sample data')
plt.xlabel('Raman shift [1/cm]')
plt.legend(loc='upper right')
plt.savefig('keras_MLP_weights' + '.png', dpi = 160, format = 'png') # Save plot
#************************************
示例13: show_attention_map
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def show_attention_map(src_words, pred_words, attention, pointer_ratio=None):
fig, ax = plt.subplots(figsize=(16, 4))
im = plt.pcolormesh(np.flipud(attention), cmap="GnBu")
# set ticks and labels
ax.set_xticks(np.arange(len(src_words)) + 0.5)
ax.set_xticklabels(src_words, fontsize=14)
ax.set_yticks(np.arange(len(pred_words)) + 0.5)
ax.set_yticklabels(reversed(pred_words), fontsize=14)
if pointer_ratio is not None:
ax1 = ax.twinx()
ax1.set_yticks(np.concatenate([np.arange(0.5, len(pred_words)), [len(pred_words)]]))
ax1.set_yticklabels('%.3f' % v for v in np.flipud(pointer_ratio))
ax1.set_ylabel('Copy probability', rotation=-90, va="bottom")
# let the horizontal axes labelling appear on top
ax.tick_params(top=True, bottom=False, labeltop=True, labelbottom=False)
# rotate the tick labels and set their alignment
plt.setp(ax.get_xticklabels(), rotation=-45, ha="right", rotation_mode="anchor")
示例14: _alex_plot_style
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def _alex_plot_style(g, colorbar=True):
"""Set plot style and colorbar for an ALEX joint plot.
"""
g.set_axis_labels(xlabel="E", ylabel="S")
g.ax_marg_x.grid(True)
g.ax_marg_y.grid(True)
g.ax_marg_x.set_xlabel('')
g.ax_marg_y.set_ylabel('')
plt.setp(g.ax_marg_y.get_xticklabels(), visible=True)
plt.setp(g.ax_marg_x.get_yticklabels(), visible=True)
g.ax_marg_x.locator_params(axis='y', tight=True, nbins=3)
g.ax_marg_y.locator_params(axis='x', tight=True, nbins=3)
if colorbar:
pos = g.ax_joint.get_position().get_points()
X, Y = pos[:, 0], pos[:, 1]
cax = plt.axes([1., Y[0], (X[1] - X[0]) * 0.045, Y[1] - Y[0]])
plt.colorbar(cax=cax)
示例15: plot_data
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import setp [as 別名]
def plot_data(X_train, y_train, plot_row=5):
counts = dict(Counter(y_train))
num_classes = len(np.unique(y_train))
f, axarr = plt.subplots(plot_row, num_classes)
for c in np.unique(y_train): # Loops over classes, plot as columns
c = int(c)
ind = np.where(y_train == c)
ind_plot = np.random.choice(ind[0], size=plot_row)
for n in range(plot_row): # Loops over rows
axarr[n, c].plot(X_train[ind_plot[n], :])
# Only shops axes for bottom row and left column
if n == 0:
axarr[n, c].set_title('Class %.0f (%.0f)' % (c, counts[float(c)]))
if not n == plot_row - 1:
plt.setp([axarr[n, c].get_xticklabels()], visible=False)
if not c == 0:
plt.setp([axarr[n, c].get_yticklabels()], visible=False)
f.subplots_adjust(hspace=0) # No horizontal space between subplots
f.subplots_adjust(wspace=0) # No vertical space between subplots
plt.show()
return