我有这个数据
10,000 12,350 11153
12,350 17,380 39524
17,380 24,670 29037
24,670 36,290 25469
通过使用matplotlib.pyplot,我想绘制一个条形图,其中bar从column0开始,到column1结束。条形表示间隔(10-12.35),条形高度表示第2列(1153)。怎么可以这样做?
谢谢
答案 0 :(得分:1)
您可以找到pyplot.bar()
here的文档。对于您的问题,您需要将column0分配给left
,将column2分配给height
,并将column1-column0分配给width
:
import io
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
s = """10000 12350 11153
12350 17380 39524
17380 24670 29037
24670 36290 25469"""
df = pd.read_table(io.StringIO(s), sep=' ', header=None, dtype='int')
plt.bar(df[0], df[2], df[1]-df[0])
plt.show()