用matplotlib绘制散点图(scatter)

-- TOC --

散点图就是点,大大小小,各种颜色。下面是个简单的代码示例:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,1,20)
y = np.sin(x)
z = np.cos(x)
size = tuple(i*300 for i in y)
color = np.random.rand(20)

fig, ax = plt.subplots()
ax.scatter(x,y,color='r',s=size,alpha=0.6)
ax.scatter(x,z,c=color,s=size,linewidth=0,marker='X')

plt.show()

效果图:

scatter

本文链接:https://cs.pynote.net/sf/python/matplotlib/202309263/

-- EOF --

-- MORE --