簡體   English   中英

如何從 matplotlib 條形圖中獲取數據

[英]How to get data from matplotlib bar chart

如何以編程方式從 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)

但是,對於條形圖,沒有線條,我不清楚等效的 object 是什么:

plt.bar([1,2,3], [4,5,6])
axis = plt.gca()
???

FWIW,這里有幾個相關的帖子(沒有 go 進入條形圖):

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)

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM