14

I have used the pandas value_counts function to provide counts of unique values:

CountStatus = pd.value_counts(df['scstatus'].values, sort=True)

Output:
200    133809
304      7217
404      2176
302       740
500       159
403         4
301         1
dtype: int64

I now want to plot these values using matplotlib i.e plt.barh(CountStatus), however I keep getting the error: ValueError: incompatible sizes: argument 'width' must be length 7 or scalar.

I'm guessing this may have something to do with the left hand column being an index column. Is there a way around this to obtain a horizontal bar chart? Do I need to convert it or specify something else in the function?

1 Answer 1

29

Update

import seaborn as sns

# test data, loads a pandas dataframe
df = sns.load_dataset('planets')

# display(df.head(3))
            method  number  orbital_period  mass  distance  year
0  Radial Velocity       1         269.300  7.10     77.40  2006
1  Radial Velocity       1         874.774  2.21     56.95  2008
2  Radial Velocity       1         763.000  2.60     19.84  2011

# plot value_counts of Series
ax = df.method.value_counts().plot(kind='barh')
ax.set_xscale('log')

enter image description here

Original Answer

I think you can use barh:

CountStatus.plot.barh()

Sample:

CountStatus = pd.value_counts(df['scstatus'].values, sort=True)
print CountStatus
AAC    8
AA     7
ABB    4
dtype: int64

CountStatus.plot.barh()

graph

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

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.