简体   繁体   中英

how to do the scatter plot for the lists or 2d array or matrix python?

 X=[[0,3,4,0,1,1],
    [0,0,0,5,1,1],
    [6,7,0,8,1,1],
    [3,6,1,5,6,1]]

Y=[12,15,11,10]

I have the lists how to do the scatter plot to visualize the X , Y to check that relationship??

Your X being in the wrong orientation, I'm using a numpy array to easily transpose it. Then it's just a matter of plotting it on the same axis, changing the colors so you can see what's what.

import numpy as np
import matplotlib.pyplot as plt

x_arr = np.array(X)
y = np.array(Y)

fig, ax = plt.subplots()

colors=list('bgrcmykw')

for i, x in enumerate(x_arr.T):
    ax.scatter(x,y, c=colors[i])

plt.show()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM