我正在尝试使用相同的功能保存两个图:
``` plot_xy(x,y,x1,y1)```
``` plot_xy(x=x,y=y,x1=x2,y1=y2)```
但是,第二个输出覆盖了第一个输出,我怎样才能改变这个来给我两个数字和 save.fig ?
下面列出了示例代码:
import numpy as np
import matplotlib.pyplot as plt
def plot_xy(x,y,x1,y1,*args, **kwargs):
A = np.amax(x1)
fig, ax = plt.subplots()
ax.plot(x, y, 'r-', label='a' )
ax.plot(x1, y1, linestyle='none', marker='^', label = 'b')
ax.set(xlabel='cm', ylabel='(d/t)',
title='ABC')
ax.grid()
ax.set_ylim(ymin=0)
ax.set_xlim(xmin=0)
ax.set_ylim(ymax=1)
ax.set_xlim(xmax=A)
plt.legend(loc = 'best')
plt.show()
fig.savefig(r'C:\...location....\test.png')
return fig
if __name__ == "__main__":
"""passing a rough estimated data"""
print (0)
x = np.linspace(0,500, num=20 )
y = np.linspace(0,0.85, num=20 )
x1 = np.linspace(0,1000, num=20 )
y1 = np.linspace(0,1000, num=20 )
x2 = np.linspace(0,2000, num=20 )
y2 = np.linspace(0,1, num=20 )
plot_xy(x,y,x1,y1)
plot_xy(x=x,y=y,x1=x2,y1=y2)
谢谢,感谢您的所有努力。