0

I have the following dataframe:

Price,Volume
6550,18
6551,5
6552,2
6553,13
......
......
......
7001,3
7002,21

I want price along one axis and volume along the other. Since this is a pandas dataframe I am under the impression I can just plot it as follows:

df.plot(kind='bar')
plt.show()

However it is plotting both columns along the same axis. I want each column on a separate axis. I have tried the following which does not work:

df.plot(kind='bar', xticks=df['Price'], yticks=df['Volume'])

Any suggestions on what i'm doing wrong would be appreciated.

2 Answers 2

1

When you plot using df.plot(kind='bar') it will use the Index for the x-axis and then plot all columns in the DataFrame as y-values.

To get around this, you can choose x and y values to be used, such as:

df.plot(x='Price', y='Volume', kind='bar')

See here for more examples of plotting using pandas.

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

Comments

1

Specify the x and y you desire by label:

df.plot(x='Price', y='Volume', kind='bar')

Here is the complete documentation:

http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.plot.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.