1
votes

I'm trying to plot the histogram using matplotlib.pyplot library.

from matplotlib import pyplot as plt
plt.hist(df["xxx"])

When I'm trying to import that library I'm getting the error:

ImportError: cannot import name 'imaging' from 'PIL'(C:\Users\Taras\AppData\Roaming\Python\Python38\site-packages\PIL_init.py)

I'm using Anaconda and Jupyter Notebook.

3

3 Answers

1
votes

Try this code as you have made it very complicated

import matplotlib.pyplot as plt
%matplotlib inline
plt.hist(df["xxx"])
1
votes

You need to change the first line of your code to the following:

import matplotlib.pyplot as plt

The second line of code is okay, but I don't understand what the third line of code is doing. What dataframe are you trying to print? I copied and pasted a dataframe from the web and then ran your code changing the first and third lines of code.

All runs good in Jupyter Lab using the python kernel.

import matplotlib.pyplot as plt
from matplotlib import pyplot    

df = pd.DataFrame({
    'name':['john','mary','peter','jeff','bill','lisa','jose'],
    'age':[23,78,22,19,45,33,20],
    'gender':['M','F','M','M','M','F','M'],
    'state':['california','dc','california','dc','california','texas','texas'],
    'num_children':[2,0,0,3,2,1,4],
    'num_pets':[5,1,0,5,2,2,3]
})

df.plot(kind='hist',x='num_children',y='num_pets',color='red')
plt.show()

The plot can be viewed at the link below.

link

0
votes

you can solve this problem by import Image lib manually

import PIL
from PIL import Image
import matplotlib.pyplot as plt