Reputation: 115
I have this data
10,000 12,350 11153
12,350 17,380 39524
17,380 24,670 29037
24,670 36,290 25469
By using matplotlib.pyplot I would like to draw a bar chart where bar starts at column0 and ends at column1. A bar would represent an interval (10 - 12.35) and bar height is column2 (1153). How could this be done?
Thank you
Upvotes: 0
Views: 26
Reputation: 5732
You can find documentation for pyplot.bar()
here. For your question, you need to assign your column0 to left
, your column2 to height
and use column1-column0 for 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()
Upvotes: 1