【发布时间】:2014-09-30 23:05:30
【问题描述】:
我正在使用 matplotlib 从 Python 中绘制数据(使用 plot 和 errorbar 函数)。我必须绘制一组完全独立且独立的图,然后调整它们的 ylim 值,以便可以轻松地进行视觉比较。
如何从每个图中检索 ylim 值,以便分别获取上下 ylim 值的最小值和最大值,并调整图以便在视觉上比较它们?
当然,我可以只分析数据并提出我自己的自定义 ylim 值...但我想使用 matplotlib 为我做这件事。关于如何轻松(有效)做到这一点的任何建议?
这是我使用 matplotlib 绘制的 Python 函数:
import matplotlib.pyplot as plt
def myplotfunction(title, values, errors, plot_file_name):
# plot errorbars
indices = range(0, len(values))
fig = plt.figure()
plt.errorbar(tuple(indices), tuple(values), tuple(errors), marker='.')
# axes
axes = plt.gca()
axes.set_xlim([-0.5, len(values) - 0.5])
axes.set_xlabel('My x-axis title')
axes.set_ylabel('My y-axis title')
# title
plt.title(title)
# save as file
plt.savefig(plot_file_name)
# close figure
plt.close(fig)
【问题讨论】:
标签: python matplotlib plot