本文整理汇总了Python中matplotlib.pyplot.margins方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.margins方法的具体用法?Python pyplot.margins怎么用?Python pyplot.margins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.margins方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: distplot_messages_per_hour
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def distplot_messages_per_hour(msgs, path_to_save):
sns.set(style="whitegrid")
ax = sns.distplot([msg.date.hour for msg in msgs], bins=range(25), color="m", kde=False)
ax.set_xticklabels(stools.get_hours())
ax.set(xlabel="hour", ylabel="messages")
ax.margins(x=0)
plt.xticks(range(24), rotation=65)
plt.tight_layout()
fig = plt.gcf()
fig.set_size_inches(11, 8)
fig.savefig(os.path.join(path_to_save, distplot_messages_per_hour.__name__ + ".png"), dpi=500)
# plt.show()
log_line(f"{distplot_messages_per_hour.__name__} was created.")
plt.close("all")
示例2: distplot_messages_per_day
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def distplot_messages_per_day(msgs, path_to_save):
sns.set(style="whitegrid")
data = stools.get_messages_per_day(msgs)
max_day_len = len(max(data.values(), key=len))
ax = sns.distplot([len(day) for day in data.values()], bins=list(range(0, max_day_len, 50)) + [max_day_len],
color="m", kde=False)
ax.set(xlabel="messages", ylabel="days")
ax.margins(x=0)
fig = plt.gcf()
fig.set_size_inches(11, 8)
fig.savefig(os.path.join(path_to_save, distplot_messages_per_day.__name__ + ".png"), dpi=500)
# plt.show()
log_line(f"{distplot_messages_per_day.__name__} was created.")
plt.close("all")
示例3: distplot_messages_per_month
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def distplot_messages_per_month(msgs, path_to_save):
sns.set(style="whitegrid")
start_date = msgs[0].date.date()
(xticks, xticks_labels, xlabel) = _get_xticks(msgs)
ax = sns.distplot([(msg.date.date() - start_date).days for msg in msgs],
bins=xticks + [(msgs[-1].date.date() - start_date).days], color="m", kde=False)
ax.set_xticklabels(xticks_labels)
ax.set(xlabel=xlabel, ylabel="messages")
ax.margins(x=0)
plt.xticks(xticks, rotation=65)
plt.tight_layout()
fig = plt.gcf()
fig.set_size_inches(11, 8)
fig.savefig(os.path.join(path_to_save, distplot_messages_per_month.__name__ + ".png"), dpi=500)
# plt.show()
log_line(f"{distplot_messages_per_month.__name__} was created.")
plt.close("all")
示例4: _show_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def _show_plot(x_values, y_values, x_labels=None, y_labels=None):
try:
import matplotlib.pyplot as plt
except ImportError:
raise ImportError('The plot function requires matplotlib to be installed.'
'See http://matplotlib.org/')
plt.locator_params(axis='y', nbins=3)
axes = plt.axes()
axes.yaxis.grid()
plt.plot(x_values, y_values, 'ro', color='red')
plt.ylim(ymin=-1.2, ymax=1.2)
plt.tight_layout(pad=5)
if x_labels:
plt.xticks(x_values, x_labels, rotation='vertical')
if y_labels:
plt.yticks([-1, 0, 1], y_labels, rotation='horizontal')
# Pad margins so that markers are not clipped by the axes
plt.margins(0.2)
plt.show()
#////////////////////////////////////////////////////////////
#{ Parsing and conversion functions
#////////////////////////////////////////////////////////////
示例5: generate_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def generate_plot(x, y, title, save_path):
"""
generates the plot given the indices and fid values
:param x: the indices (epochs)
:param y: fid values
:param title: title of the generated plot
:param save_path: path to save the file
:return: None (saves file)
"""
font = {'family': 'normal', 'size': 20}
matplotlib.rc('font', **font)
plt.figure(figsize=(10, 6))
annot_min(x, y)
plt.margins(.05, .05)
plt.title(title)
plt.xlabel("Epochs")
plt.ylabel("FID scores")
plt.plot(x, y, linewidth=4)
plt.tight_layout()
plt.savefig(save_path, bbox_inches='tight')
示例6: generate_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def generate_plot(x, y, title, save_path):
"""
generates the plot given the indices and is values
:param x: the indices (epochs)
:param y: IS values
:param title: title of the generated plot
:param save_path: path to save the file
:return: None (saves file)
"""
font = {'family': 'normal', 'size': 20}
matplotlib.rc('font', **font)
plt.figure(figsize=(10, 6))
annot_max(x, y)
plt.margins(.05, .05)
plt.title(title)
plt.xlabel("Epochs")
plt.ylabel("Inception scores")
plt.ylim(0, max(y) + 2)
plt.plot(x, y, linewidth=4)
plt.tight_layout()
plt.savefig(save_path, bbox_inches='tight')
示例7: save_data_and_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def save_data_and_plot(self, data, filename, xlabel, ylabel):
"""
Produce a plot of performance of the agent over the session and save the relative data to txt
"""
min_val = min(data)
max_val = max(data)
plt.rcParams.update({'font.size': 24}) # set bigger font size
plt.plot(data)
plt.ylabel(ylabel)
plt.xlabel(xlabel)
plt.margins(0)
plt.ylim(min_val - 0.05 * abs(min_val), max_val + 0.05 * abs(max_val))
fig = plt.gcf()
fig.set_size_inches(20, 11.25)
fig.savefig(os.path.join(self._path, 'plot_'+filename+'.png'), dpi=self._dpi)
plt.close("all")
with open(os.path.join(self._path, 'plot_'+filename + '_data.txt'), "w") as file:
for value in data:
file.write("%s\n" % value)
开发者ID:AndreaVidali,项目名称:Deep-QLearning-Agent-for-Traffic-Signal-Control,代码行数:24,代码来源:visualization.py
示例8: plotAdriansFile
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def plotAdriansFile():
abf = pyabf.ABF(PATH_DATA+"/190619B_0003.abf")
print(abf)
# OUTPUT:
# ABF (version 1.8.3.0) with 2 channels (mV, pA),
# sampled at 20.0 kHz, containing 10 sweeps,
# having no tags, with a total length of 0.28 minutes,
# recorded with protocol "IV_FI_IN0_saray".
plt.figure(figsize=(10, 4))
plt.grid(alpha=.2, ls='--')
for sweepNumber in abf.sweepList:
abf.setSweep(sweepNumber)
plt.plot(abf.sweepX, abf.sweepY, label=f"sweep {sweepNumber+1}")
plt.margins(0, .1)
plt.legend(fontsize=8)
plt.title(abf.abfID+".abf")
plt.ylabel(abf.sweepLabelY)
plt.xlabel(abf.sweepLabelX)
plt.tight_layout()
plt.show()
示例9: makeFigure1
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def makeFigure1(colormap):
abf=pyabf.ABF("../../data/17o05028_ic_steps.abf")
plt.figure(figsize=(6,3))
for sweep in abf.sweepList[::3]:
color = plt.cm.get_cmap(colormap)(sweep/abf.sweepCount)
abf.setSweep(sweep)
plt.plot(abf.dataX,abf.dataY,color=color)
plt.margins(0,.1)
plt.axis([0,1,None,None])
plt.gca().axis('off') # remove square around edges
plt.xticks([]) # remove x labels
plt.yticks([]) # remove y labels
plt.tight_layout()
plt.savefig("_output/1_%s.png"%colormap,dpi=150)
plt.show()
plt.close()
return
示例10: makeFigure2
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def makeFigure2(colormap):
abf=pyabf.ABF("../../data/17o05026_vc_stim.abf")
plt.figure(figsize=(6,3))
for sweep in abf.sweepList[::-1]:
color = plt.cm.get_cmap(colormap)(sweep/abf.sweepCount)
abf.setSweep(sweep)
abf.dataY[:-int(abf.pointsPerSec*1)]=np.nan
abf.dataY+=4*sweep
plt.plot(abf.dataX+.05*sweep,abf.dataY,color=color,alpha=.7)
plt.margins(0,0)
plt.gca().axis('off') # remove square around edges
plt.xticks([]) # remove x labels
plt.yticks([]) # remove y labels
plt.tight_layout()
plt.savefig("_output/2_%s.png"%colormap,dpi=150)
plt.show()
plt.close()
return
示例11: demo_02a_plot_matplotlib_sweep
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def demo_02a_plot_matplotlib_sweep(self):
"""
## Plot a Sweep with Matplotlib
Matplotlib is a fantastic plotting library for Python. This example
shows how to plot an ABF sweep using matplotlib.
ABF `setSweep()` is used to tell the ABF class what sweep to load
into memory. After that you can just plot `sweepX` and `sweepY`.
"""
import pyabf
abf = pyabf.ABF("data/abfs/17o05028_ic_steps.abf")
abf.setSweep(14)
plt.figure(figsize=self.figsize)
plt.plot(abf.sweepX, abf.sweepY)
plt.grid(alpha=.2) # ignore
plt.margins(0, .1) # ignore
plt.tight_layout() # ignore
self.saveAndClose()
示例12: demo_03a_decorate_matplotlib_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def demo_03a_decorate_matplotlib_plot(self):
"""
## Decorate Plots with ABF Information
The ABF class provides easy access to lots of information about the ABF.
This example shows how to use these class methods to create a prettier
plot of several sweeps from the same file.
"""
import pyabf
abf = pyabf.ABF("data/abfs/17o05028_ic_steps.abf")
plt.figure(figsize=self.figsize)
plt.title("pyABF and Matplotlib are a great pair!")
plt.ylabel(abf.sweepLabelY)
plt.xlabel(abf.sweepLabelX)
for i in [0, 5, 10, 15]:
abf.setSweep(i)
plt.plot(abf.sweepX, abf.sweepY, alpha=.5, label="sweep %d" % (i))
plt.margins(0, .1) # ignore
plt.tight_layout() # ignore
plt.grid(alpha=.2) # ignore
plt.legend()
self.saveAndClose()
示例13: demo_08a_xy_offset
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def demo_08a_xy_offset(self):
"""
## Plot Sweeps in 3D
The previous example how to plot stacked sweeps by adding a Y offset
to each sweep. If you add an X and Y offset to each sweep, you can
create a 3D effect.
"""
import pyabf
abf = pyabf.ABF("data/abfs/171116sh_0018.abf")
plt.figure(figsize=self.figsize)
for sweepNumber in abf.sweepList:
abf.setSweep(sweepNumber)
i1, i2 = 0, int(abf.dataRate * 1) # plot part of the sweep
dataX = abf.sweepX[i1:i2] + .025 * sweepNumber
dataY = abf.sweepY[i1:i2] + 15 * sweepNumber
plt.plot(dataX, dataY, color='C0', alpha=.5)
plt.gca().axis('off') # hide axes to enhance floating effect
plt.margins(.02, .02) # ignore
plt.tight_layout() # ignore
self.saveAndClose()
示例14: demo_11a_gap_free
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def demo_11a_gap_free(self):
"""
## Plotting Gap-Free ABFs
The pyABF treats every ABF like it's episodic (with sweeps). As such,
gap free ABF files are loaded as if they were episodic files with
a single sweep. When an ABF is loaded, `setSweep(0)` is called
automatically, so the entire gap-free set of data is already available
by plotting `sweepX` and `sweepY`.
"""
import pyabf
abf = pyabf.ABF("data/abfs/abf1_with_tags.abf")
plt.figure(figsize=self.figsize)
plt.plot(abf.sweepX, abf.sweepY, lw=.5)
plt.axis([725, 825, -150, -15])
plt.ylabel(abf.sweepLabelY)
plt.xlabel(abf.sweepLabelX)
plt.title("Example Gap Free File")
plt.margins(0, .1) # ignore
plt.grid(alpha=.2) # ignore
self.saveAndClose()
示例15: plot_scatter
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import margins [as 别名]
def plot_scatter(pt, data_name, plt_path):
fig = plt.figure()
fig.set_size_inches(20.0 / 3, 20.0 / 3)
ax = fig.gca(projection='3d')
ax.set_aspect('equal')
ax.grid(color='r', linestyle='-',)
ax.set_yticklabels([])
ax.set_xticklabels([])
ax.set_zticklabels([])
X = pt[:, 0]
Y = pt[:, 1]
Z = pt[:, 2]
scat = ax.scatter(X, Y, Z, depthshade=True, marker='.')
max_range = np.array([X.max() - X.min(), Y.max() - Y.min(), Z.max() - Z.min()]).max() / 2.0
mid_x = (X.max() + X.min()) * 0.5
mid_y = (Y.max() + Y.min()) * 0.5
mid_z = (Z.max() + Z.min()) * 0.5
ax.set_xlim(mid_x - max_range, mid_x + max_range)
ax.set_ylim(mid_y - max_range, mid_y + max_range)
ax.set_zlim(mid_z - max_range, mid_z + max_range)
plt.margins(0, 0)
fig.savefig(os.path.join(plt_path, data_name.replace('.dat', '.png')), format='png', transparent=True, dpi=300, pad_inches=0, bbox_inches='tight')