Python Forum
Problem with Matplotlib.pyplot - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Problem with Matplotlib.pyplot (/thread-12339.html)



Problem with Matplotlib.pyplot - LTMP - Aug-21-2018

Hi guys,

The codes in green below for importing csv was fine.

According to an online tutorial, the codes in red are supposed to generate a whole histogram containing xlabels and ylabels. However, when I tried it in Spyder, I computed the code in red individually and got each part of the graph separately. The "show.plt()" at the end returned a blank histogram with only ylabel.

Thanks for your help!

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

import pandas as pd
df_swing = pd.read_csv ('D:\\Dev\\DataCamp\\2008_swing_states.csv')

plt.hist(df_swing['dem_share'])
plt.xlabel('percent of votes for Obama')
plt.ylabel('number of counties')
plt.show()



RE: Problem with Matplotlib.pyplot - ichabod801 - Aug-21-2018

That's the way matplotlib works. Each function adds something to the graph. Running them individually only gives you the individual parts. You should just run them all together.