from matplotlib.pyplot import MultipleLocator
fig=plt.figure()
plt.plot(geatpy_cgq_qzy_f_da["n"],geatpy_cgq_qzy_f_da["X_dabi"],label="Lx2")
plt.plot(geatpy_cgq_qzy_f_2d2a["n"],geatpy_cgq_qzy_f_2d2a["X_dabi"],label="Lx3")
plt.plot(geatpy_cgq_qzy_f_2xyz["n"],geatpy_cgq_qzy_f_2xyz["X_dabi"],label="Lx4")
plt.scatter(geatpy_cgq_qzy_f_2xyz["n"],geatpy_cgq_qzy_f_2xyz["x"],label="Lx0")
# x_major_locator=MultipleLocator(0.5)
y_major_locator=MultipleLocator(10)
ax=plt.gca()
# ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
# plt.xlim(-0.5,11)
plt.ylim(1860,1900)
plt.legend(bbox_to_anchor =(1.03,0),loc=3,borderaxespad=0)
plt.xlabel("n",fontsize=16)
plt.ylabel("x/mm",fontsize=16)
fig.savefig('H:\\论文\\末端补偿关节\\Nx01.png',dpi=600,bbox_inches='tight')
plt.show()
def plot3d_xyz1(xsj_qzy_cgq_all,save_path,enable=False,elev=45, azim=-45,label0="L00",label1="L10"):
fig=plt.figure(num=0,figsize=(8, 5))
ax=fig.gca(projection="3d")
ax.view_init(elev=elev, azim=azim)
ax.set_xlabel('x')
ax.set_ylabel("y")
ax.set_zlabel("z")
ax.scatter(xsj_qzy_cgq_all["x"],xsj_qzy_cgq_all["y"],xsj_qzy_cgq_all["z"],c="r",label=label0)
ax.scatter(xsj_qzy_cgq_all["X_dabi"],xsj_qzy_cgq_all["Y_dabi"],xsj_qzy_cgq_all["Z_dabi"],c="g",marker="|",label=label1)
plt.legend(bbox_to_anchor =(0.9,0),loc=3,borderaxespad=0)
plt.show()
if enable==True:
fig.savefig(save_path,dpi=600,bbox_inches='tight')
多图并列: 转自
https://www.cnblogs.com/chaoren399/p/5792168.html
#!/etc/bin/python
#coding=utf-8
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
np.random.seed(2000)
y = np.random.standard_normal((10, 2))
plt.figure(figsize=(7,5))
plt.subplot(211) #两行一列,第一个图
plt.plot(y[:,0], lw = 1.5,label = '1st')
plt.plot(y[:,0], 'ro')
plt.grid(True)
plt.legend(loc = 0) #图例位置自动
plt.axis('tight')
plt.ylabel('value')
plt.title('A simple plot')
plt.subplot(212) #两行一列.第二个图
plt.plot(y[:,1],'g', lw = 1.5, label = '2nd')
plt.plot(y[:,1], 'ro') plt.grid(True)
plt.legend(loc = 0)
plt.xlabel('index')
plt.ylabel('value 2nd')
plt.axis('tight') plt.show()