3

I am trying to make a simple bar chart: the height being frequencies of values in a Dataframe column

I have been running into this error: ValueError: incompatible sizes: argument 'height' must be length 1 or scalar

Code:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pylab as pl
matplotlib.style.use('ggplot')
flags = [200, 201, 211, 237, 239, 250, 254, 255]
frequencies = [158,  87,   5,   4]
length = len(flags)
plt.bar(length, frequencies.values, align='center')
plt.show()
1
  • When you say "height being frequencies of values" I hear "histogram". If you indeed want a histogram, pandas has a method built in for creating those: df['foo'].hist() Commented Dec 4, 2016 at 4:24

1 Answer 1

3

Well as far as I can see in the documentation of matplotlib.pyplot.bar, arguments left and height must be the same length:

>>> plt.bar(range(len(frequencies)), frequencies, align='center')
>>> plt.show()

enter image description here

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

1 Comment

thank you, that's what i thought may have been the issues but i was not sure

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.