How Do I Convert Csv Data Into Bar Chart?
I have already done a line plot using the csv data and import matplotlib.pyplot as plt charge, total and year have already been append by rows. My code plt.plot(year, charge, '-g'
Solution 1:
There is an example in the matplotlib site and you can find another approach of your issue here. Basically, you just shift the x values by width. Here is the relevant bit:
import numpy as np
import matplotlib.pyplot as plt
# create sample data as np.array in the provided format year | chargeable | total
arr = np.array([[2017, 375873, 78833], [2018, 783893, 98288]])
ind = np.arange(arr.shape[0]) # the x locations for the groups
width = 0.35 # the width of the bars
fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(ind, arr[:, 2], width, color='royalblue')
rects2 = ax.bar(ind+width, arr[:, 1], width, color='seagreen')
# add some
ax.set_ylabel('(S$)')
ax.set_ylabel('Year')
ax.set_title('Chargeable and Total Income VS Year')
ax.set_xticks(ind + width / 2)
ax.set_xticklabels( arr[:, 0] )
ax.legend( (rects1[0], rects2[0]), ('Chargeable Income', 'Total Income') )
plt.show()
Post a Comment for "How Do I Convert Csv Data Into Bar Chart?"