0

I am trying to plot a histogram in python based on two columns ie State and Production. My dataframe looks like below:

State Year Area production
AB    2014 20000 21674
BS    2014 35000 116074
TS    2014 20000 32678

My requirement is to have States on x-axis and their production level at y-axis

Below is the code i have written:

%matplotlib inline
fig=plot.figure(figsize=(8,10))
ax=fig.gca()
Pulse_yield['State'].hist(x, bin =30)
ax.set_title('Yield in 2014')
ax.set_xlabel('States')
ax.set_ylabel('Production')
plot.xticks(rotation=90)

Issue is: on x-axis, individual values are populating for each State but on y-axis , it is showing as 0,10,20,30, 40 etc and not the value I have in Production column.

Histogram

7
  • 1
    It looks like you want to plot a bar chart instead of a histogram. Commented Mar 29, 2018 at 9:25
  • The point is you cannot draw a histogram of two variables because a histogram shows the values on the x axis and the frequency of those values on the y axis. Commented Mar 29, 2018 at 10:30
  • @ImportanceOfBeingErnest.. Thanks for clarifying :) Could you please suggest which plot can be used for my purpose. Commented Mar 29, 2018 at 10:33
  • Yes, a bar plot. I marked this question as duplicate. Commented Mar 29, 2018 at 10:34
  • @ImportanceOfBeingErnest.. Could you please suggest how to do that .. or provide me the reference question for Bar Plot. Commented Mar 29, 2018 at 10:36

1 Answer 1

0

plt.gca gets the current axes, creating one if needed. It is only equivalent in the simplest 1 axes case.

The preferred way is to use plt.subplots() :

fig, ax = plt.subplots(1, 1)

or

fig, (ax1, ax2) = plt.subplots(2, 1)

and so on.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.