以下是使用matplotlib的散点图生成附加图像的一小段代码。
我正在尝试获取一个“图例”,显示几个点的大小和相应的“z值”。
除了自己构建之外,是否有类似于这样的东西?一个与色条类似的“大小”类比?
![Output image from code.](https://istack.dev59.com/iP95a.webp)
除了自己构建之外,是否有类似于这样的东西?一个与色条类似的“大小”类比?
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(8,6))
inset = fig.add_subplot(111)
np.random.seed(0) # so the image is reproducible
x1 = np.random.rand(30)
y1 = np.random.rand(30)
z1 = np.random.rand(30)
axis = inset.scatter(x1,y1,s=z1*100,c=z1,vmin=0,vmax=1)
inset.set_xlabel("X axis")
inset.set_ylabel("Y axis")
cbar = fig.colorbar(axis,ticks=[0,0.5,1])
cbar.ax.set_yticklabels(["Low","Medium","High"])
plt.savefig('scatterplot-zscale.png',bbox_inches='tight')