我有(x,y)的8对,例如(x1,y1),.....(x8,y8),我想要一个具有4个子图的图(都为散点图),其中第一个子图显示(x1,y1)和(x2,y2),第二个子图显示(x3,y3)和(x4,y4),依此类推。我使用了以下代码,但有两个问题:
代码是:
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)...
问题是,您声明了一个子图对象(fig
,其子图可通过ax[i,j]
访问,然后通过为它分配一个常规ax[i,j]
对象来覆盖访问变量plt.scatterplot
。