Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

My Madplotlib chart will not show in Jupyter Ntbk. I get <Figure size 640x480 with 1 Axes> Am I leaving something out?

Here's my code:

from itertools import groupby

import csv import matplotlib.pyplot as plt

input_file = "iris.csv" with open(input_file, 'r') as iris_data: irises = list(csv.reader(iris_data))

colors = {"Iris-setosa": "#2B5B84", "Iris-versicolor": "g", "Iris-virginica": "purple"}

irises.pop()

for species, group in groupby(irises, lambda i: i[4]): categorized_irises = list(group) sepal_lengths = [float(iris[0]) for iris in categorized_irises] sepal_widths = [float(iris[1]) for iris in categorized_irises] plt.scatter(sepal_lengths, sepal_widths, s=10, c=colors[species], label=species)

plt.title("Fisher's Iris Data Set", fontsize = 12) plt.xlabel("sepal_lengths (cm)", fontsize = 10) plt.ylabel("sepal_widths (cm)", fontsize = 10) plt.legend(loc='upper right')

plt.show()

1 Answer

I compared your code to the video and it is the same. I was able to run it and display the plot. You could try the suggestion here

I added %matplotlib inline just before import matplotlib.pyplot as plt and it made no difference. The plot displayed the same. When I tried %matplotlib notebook however the plot disappeared.

Your code formatted with markdown:

from itertools import groupby

import csv
import matplotlib.pyplot as plt

input_file = "iris.csv"

with open(input_file, 'r') as iris_data:
    irises = list(csv.reader(iris_data))

colors = {"Iris-setosa": "#2B5B84", "Iris-versicolor": "g", "Iris-virginica": "purple"}

irises.pop()

for species, group in groupby(irises, lambda i: i[4]):
    categorized_irises = list(group)
    sepal_lengths = [float(iris[0]) for iris in categorized_irises]
    sepal_widths = [float(iris[1]) for iris in categorized_irises]
    plt.scatter(sepal_lengths, sepal_widths, s=10, c=colors[species], label=species)

plt.title("Fisher's Iris Data Set", fontsize = 12)
plt.xlabel("sepal_lengths (cm)", fontsize = 10)
plt.ylabel("sepal_widths (cm)", fontsize = 10)
plt.legend(loc='upper right')

plt.show()