2

I'm currently doing this tutorial here: http://nbviewer.ipython.org/urls/bitbucket.org/hrojas/learn-pandas/raw/master/lessons/01%20-%20Lesson.ipynb

I am currently on the last section where you have to plot a graph. I am running the code in my own idle and not iPython. Here is my code:

q=df['Births'].plot()

MaxValue = df['Births'].max()

MaxName = df['Names'][df['Births'] == df['Births'].max()].values

Text = str(MaxValue) + " - " + MaxName

plt.annotate(Text, xy=(1, MaxValue), xytext=(8,0),xycoords=('axes fraction', 'data'), textcoords ='offset points')
print("The most popular name")
df[df['Births'] == df['Births'].max()]

print(q)

The output I am getting is:

The most popular name
Axes(0.125,0.1;0.775x0.8)

How do I get it to actually show the graph?

1
  • Documentation example from matplotlib here Commented Jul 7, 2015 at 12:13

2 Answers 2

2

Adding plt.show() should do the trick, although if I may make a recomendation..this data would be better represented by a bar chart. Something like the following should do the trick:

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

df = pd.DataFrame(data = BabyDataSet, columns=['Names', 'Births'])

matplotlib.style.use('ggplot')

ax = df['Births'].plot(kind = 'bar')
ax.set_xticklabels(df.Names)

ax.annotate('Most Popular Name: {}: {} births'.format(df.max().Names, df.max().Births),
        xy=(1, 1), 
        xytext=(1, 800))

ax.set_title("Number of Births by Name")
ax.set_ylabel("No. Births")

plt.show()

enter image description here

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

Comments

1

If you are not in interactive mode, you might need to add plt.figure() before your code, and plt.show() after.

Comments

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.