Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plot is not showing up
#1
* I am pretty new to Python *

I am trying to create a python program for machine learning.
The code shown below is expected to create a plot but program runs and comes out without any error but no plot. Am I making any mistake?

# Imports
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
import numpy as np

# load the data with load_iris from sklearn
data = load_iris()
features = data['data']
feature_names = data['feature_names']
target = data['target']

#print("features\n",features)
#print("feature names\n",feature_names)
#print("target\n",target);
print("data\n",data)

for t,marker,c in zip(range(3),">ox","rgb"):
    # plot each class on its own to get different colored markers
    plt.scatter(features[target == t,0],
                features[target == t,1],
                marker=marker,
                c=c)
Reply
#2
It looks the problem is you don't call plt.show() at the end
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

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