Bar plot with x and y axis
Bar plot with x and y axis
Now i am getting the bar chart as i attached above, kindly let me know why i am getting range in x-axis. Where is the mistake
This is sample dataset.
Plant Country Fault Level Type Fault Location Fault_loss
0 001 ESPP1 TH All Plant Internal PV Plant Incidents NaN 2.5
1 001 ESPP1 TH All Plant External Grid Forced Outage NaN 1.3
2 001 ESPP1 TH All Plant External Grid Forced Outage NaN 0.3
3 001 ESPP1 TH All Plant External Grid Forced Outage NaN 31.9
4 001 ESPP1 TH All Plant External Grid Forced Outage NaN 0.3
5 001 ESPP1 TH All Plant External Grid Forced Outage NaN 0.1
6 001 ESPP1 TH All Plant External Grid Forced Outage NaN 0.1
7 001 ESPP1 TH All Plant External Grid Forced Outage NaN 0.4
8 001 ESPP1 TH All Plant External Grid Forced Outage NaN 4.0
9 001 ESPP1 TH All Plant External Grid Forced Outage NaN 0.0
10 001 ESPP1 TH All Plant External Grid Forced Outage NaN 8.5
I am trying to plot bar plot dynamically with 2 attributes country and fault loss.
unique_country = data2.Country.unique()
for i in range(len(unique_country)):
plant = data2.groupby(data2["Country"]).get_group(unique_country[i]).Fault_loss.sum()
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.set_xlabel(unique_country[i])
ax1.set_ylabel('Fault loss')
ax1.set_title("Country wise Sum of Fault_loss")
plt.plot(plant)
plt.show()
Here i am getting only the outer box but not able to get the bar plot. It is displaying plain outer layer. May i know were i am went wrong here. I know this is very silly mistake but not able to identify that.
My updated code,
unique_plant = data2.Plant.unique()
for i in range(len(unique_plant)):
plant = data2.groupby(data2["Plant"]).get_group(unique_plant[i]).Fault_loss.sum()
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.set_xlabel(unique_plant[i])
ax1.set_ylabel('Fault loss')
ax1.set_title("plant wise vs Fault_loss")
plt.bar(plant, height=2.1, width= 1.1)
plt.show()
Why are using
plt.plot
? I think you need plt.bar
for what you want.– Paula Thomas
Jun 29 at 11:53
plt.plot
plt.bar
dataset is updated
– sangeetha sivakumar
Jun 29 at 11:55
have you tried
plant.plot.bar()
?– Scotty1-
Jun 29 at 11:56
plant.plot.bar()
If i give plt.bar , i am getting this below error.TypeError: <lambda>() missing 1 required positional argument: 'height'
– sangeetha sivakumar
Jun 29 at 11:56
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
dataset is not clear. Please make it easy to read.
– Mufeed
Jun 29 at 11:48