Python Forum
how to nest loop for 4*4 scatter plot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to nest loop for 4*4 scatter plot
#1
Hello,

I am new and trying to write a 4 by 4 scatter matrix using for loop and subplot functions. The data is iris. I have run this code but nothing is getting returned. Please review it and advise,what went wrong, thanks.

from sklearn import datasets
import matplotlib.pyplot as plt
%matplotlib inline
iris = datasets.load_iris()

X=iris.data
Y=iris.target

t= 1
for i in range (0,4):
    for j in range (0,4):
        ax = fig.add_subplot(4,4,t)
        ax.scatter(X[:, i], X[:, j], c=Y, cmap=plt.cm.Paired)
        t=t+1
        plt.show()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  For Loop: To see plot for different columns JaneTan 0 973 Dec-14-2022, 05:55 AM
Last Post: JaneTan
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,685 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
Shocked plt.scatter() errors asja2010 0 1,491 Oct-13-2022, 08:15 AM
Last Post: asja2010
  How to invert scatter plot axis Mark17 3 2,534 Sep-22-2021, 04:45 PM
Last Post: jefsummers
  Animated scatter plot maximan 0 1,650 Jan-18-2021, 03:53 PM
Last Post: maximan
  How to plot intraday data of several days in one plot mistermister 3 2,923 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  Group scatter plots Mekala 0 1,658 Jul-23-2020, 02:18 PM
Last Post: Mekala
  How to create Custom Buttons for 3D Scatter plots in Plotly? yourboyjoe 0 2,142 Jun-01-2020, 10:58 PM
Last Post: yourboyjoe
  colorbar for scatter shows no negatives values... gil 0 1,539 Apr-15-2020, 12:45 AM
Last Post: gil
  plotly.graph_objs - Scatter mode error sambanerjee 14 9,165 Mar-18-2020, 02:54 PM
Last Post: sambanerjee

Forum Jump:

User Panel Messages

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