如何从matplotlib条形图中以编程方式检索数据?我可以按如下所示对matplotlib折线图进行操作,所以也许我已经很接近了:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,5,6])
axis = plt.gca()
line = axis.lines[0]
x_plot, y_plot = line.get_xydata().T
print("x_plot: ", x_plot)
print("y_plot: ", y_plot)
但是,对于条形图,没有线,并且我不清楚等效对象是什么:
plt.bar([1,2,3], [4,5,6])
axis = plt.gca()
???
FWIW,这是一些相关的帖子(不包括在条形图中):
matplotlib.pyplot.bar
返回BarContainer
对象 的API
matplotlib.patches.Rectangle
提供方法的完整说明Patch
。import matplotlib.pyplot as plt
rects = plt.bar([1,2,3], [4,5,6])
for rect in rects:
print(rect)
xy = rect.get_xy()
x = rect.get_x()
y = rect.get_y()
height = rect.get_height()
width = rect.get_width()
[out]:
Rectangle(xy=(0.6, 0), width=0.8, height=4, angle=0)
Rectangle(xy=(1.6, 0), width=0.8, height=5, angle=0)
Rectangle(xy=(2.6, 0), width=0.8, height=6, angle=0)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句