Python Forum

Full Version: Problem with Matplotlib.pyplot
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
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.