Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在不同的图上绘制散点图_Python_Matplotlib - Fatal编程技术网

Python 在不同的图上绘制散点图

Python 在不同的图上绘制散点图,python,matplotlib,Python,Matplotlib,我有一个创建散点图的自定义函数: def scatterplot(df): enrich,number=separate_types(df) fig=plt.figure(1) axes=plt.gca() plt.xlabel("P") plt.ylabel("E") for i in range(len(enrich)): if enrich["Treatment"][i]=="C"

我有一个创建散点图的自定义函数:

def scatterplot(df):
  
 enrich,number=separate_types(df) 
 fig=plt.figure(1)
 axes=plt.gca()

 plt.xlabel("P")
 plt.ylabel("E")
 for i in range(len(enrich)):
    if enrich["Treatment"][i]=="C":
        color="tab:blue"
    else:
        color="tab:orange"
    plt.errorbar(x=number["mean"][i],y=enrich["mean"][i],yerr=enrich["stdev"][i],xerr=number["stdev"][i],color=color,marker=".",label=enrich["Treatment"][i])

handles, labels = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels, handles))
plt.legend(by_label.values(), by_label.keys())
return(fig)
这个想法是得到一个有x和y误差的散点图,以及一个基于不同列的颜色方案

我注意到,如果我使用d1(总共5分)这样:

scatterplot(d1)
scatterplot(d2)
然后是另一个d2(总共5分),如下所示:

scatterplot(d1)
scatterplot(d2)

我会得到一个10点的图。我想要2个5点的图(每个都属于d1和d2)。如何修改函数以适应这种情况?

文档强调了发生这种行为的原因

通过调用
fig=plt.figure(1)
如果没有其他具有相同标识符的图形,则创建一个新图形。在您的情况下,这意味着
1
。在您的情况下,标识符为
1
的地物始终会恢复,并且不会创建新地物

从文件中:

num: int or str or Figure, optional

A unique identifier for the figure.

If a figure with that identifier already exists, 
this figure is made active and returned. An integer 
refers to the Figure.number attribute, a string refers to 
the figure label.

是的,这就解决了。谢谢