使用matplolib子图在散点图中绘制8对(x,y)对

问题描述 投票:0回答:1

我有(x,y)的8对,例如(x1,y1),.....(x8,y8),我想要一个具有4个子图的图(都为散点图),其中第一个子图显示(x1,y1)和(x2,y2),第二个子图显示(x3,y3)和(x4,y4),依此类推。我使用了以下代码,但有两个问题:

  1. 仅在一个子图中绘制所有对。
  2. [例如,当我想将x标签或y标签添加到第一个子图并且我使用ax [0,0] .set_xlabel(“ x1-x2”)时,它返回“ PathCollection”对象没有属性'set_xlabel'“]] >
  3. 代码是:

import matplotlib.pyplot as plt
fig, ax = plt.subplots(2, 2,figsize=(12,12))
ax[0,0] = plt.scatter(x1,y1,color='red', marker = ".")#,order=order)
ax[0,0] = plt.scatter(x2,y2,color='blue', marker = ".")#,order=order)
ax[0,1] = plt.scatter(x3,y3,color='red', marker = ".")#,order=order)
ax[0,1] = plt.scatter(x4,y4,color='blue', marker = ".")#,order=order)
ax[1,0] = plt.scatter(x5,y5,color='red', marker = ".")#,order=order)
ax[1,0] = plt.scatter(x6,y6,color='red', marker = ".")#,order=order)
ax[1,1] = plt.scatter(x7,y7,color='red', marker = ".")#,order=order)
ax[1,1] = plt.scatter(x8,y8,color='red', marker = ".")#,order=order)  

任何帮助将不胜感激。

我有(x,y)的8对,例如(x1,y1),.....(x8,y8),我想要一个具有4个子图的图(都为散点图),其中第一个子图显示(x1,y1)和(x2,y2),第二个子图显示(x3,y3)...

python python-3.x matplotlib
1个回答
0
投票

问题是,您声明了一个子图对象(fig,其子图可通过ax[i,j]访问,然后通过为它分配一个常规ax[i,j]对象来覆盖访问变量plt.scatterplot

© www.soinside.com 2019 - 2024. All rights reserved.