I'm new to data science. I wrote this script for plotting all different kinds of iris data set scatter plot. trying not to plot something with itself . how can I optimize my code ?
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
iris=load_iris()
list1=[]
fig, ax =plt.subplots(nrows=3,ncols=2,figsize=(10,10))
for ii in range(4):
for jj in range(1,4):
if ii==jj:
break
if ii*jj not in list1[1::2]:
list1.extend((ii+jj,ii*jj))
elif ii+jj in list1[::2]:
break
a=ii
b=jj
x_index=ii
y_index=jj
colors=['blue','red','green']
if ii==0:
b=b-1
elif jj==1:
a=a-2
b,a=a,b
elif ii==3:
a=a-1
b=b-1
a,b=b,a
for label , color in zip(range(len(iris.target_names)),colors):
ax[b,a].scatter(iris.data[iris.target==label,x_index]
, iris.data[iris.target==label,y_index]
, label=iris.target_names[label]
, color=color)
ax[b,a].set_xlabel(iris.feature_names[x_index])
ax[b,a].set_ylabel(iris.feature_names[y_index])
ax[b,a].legend(loc="upper right")
fig.tight_layout()
fig.show()
how would you write it if it was you?
I appreciate any help.