Python Forum
Problem with Matplotlib.pyplot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Matplotlib.pyplot
#1
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()
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  matplotlib.pyplot issue lonaveia 2 2,316 Jul-28-2020, 02:40 PM
Last Post: hussainmujtaba
  matplotlib.pyplot functions create new figures instead of applying to the current one karkas 2 2,049 Jul-09-2020, 08:32 AM
Last Post: karkas
  How does pyplot know what was plotted by the output of pandas.DataFrame(...).cumprod( codeowl 2 2,163 Mar-28-2020, 08:27 AM
Last Post: j.crater
  zooming in pyplot window SchroedingersLion 0 2,174 Aug-02-2019, 02:59 PM
Last Post: SchroedingersLion
  How to draw rectangles in pyplot? SuchtyTV 4 6,382 Jul-14-2019, 02:41 PM
Last Post: SuchtyTV
  How to arrange the four pictures of a matplotlib.pyplot? vokoyo 0 2,742 Apr-04-2019, 10:58 PM
Last Post: vokoyo
  matplotlib pyplot ginput issue MLiljeroth 0 3,518 Oct-12-2018, 07:12 AM
Last Post: MLiljeroth

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020