我有以下要求显示散点图:

这是我的代码:
# Define Data
x = result.iloc[:,6] #R Score
y = result.iloc[:,11] #FM Score
# Create Figure
fig, ax = plt.subplots()
ax.set_ylabel('frequency & monetary score')
ax.set_xlabel('recency score')
ax.scatter(x, y,c=z, cmap='viridis', alpha=0.5)
ax.legend(*sc.legend_elements(), title="CLUSTER",loc='lower center',
bbox_to_anchor=(0.5, 1.05),ncol=5, fancybox=True, shadow=True)
ax.grid(True)
plt.show()产出:

问题是,我不知道如何在特定的网格位置上创建自定义的分层(例如x轴的冠军杯层:4-5和y-轴:6-10)。
这可以使用matplotlib吗?
谢谢
发布于 2022-06-11 15:45:51
对于那些跌跌撞撞的问题,我找到了解决方案,使用图像网格。
# Define Data
x = result.iloc[:,6] #R Score
y = result.iloc[:,11]/2 #FM Score
extent = (0,5, 0, 5)
# Create Figure
fig, ax = plt.subplots()
ax.set_ylabel('frequency & monetary score')
ax.set_xlabel('recency score')
ax.scatter(x, y,c=z, cmap='viridis', alpha=0.5,zorder=2)
ax.legend(*sc.legend_elements(), title="CLUSTER",loc='lower center',
bbox_to_anchor=(0.5, 1.05),ncol=5, fancybox=True, shadow=True)
ax.grid(True)
layer_img=plt.imread("assets/rfm.JPG")
plt.imshow(layer_img,zorder=1, extent=extent)
plt.show()结果:

https://stackoverflow.com/questions/72583068
复制相似问题