试下并修改这个,低手,很不简洁
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
df = pd.DataFrame({
'group': [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000],
'ACC': [0.8001, 0.8101, 0.8202, 0.8306, 0.8605, 0.8453, 0.8788, 0.8966],
'NMI': [0.8002, 0.8103, 0.8232, 0.8406, 0.8505, 0.8400, 0.8701, 0.8506],
'ARI': [0.8003, 0.8133, 0.8242, 0.8206, 0.8105, 0.8100, 0.8601, 0.8306],
})
df2=df.set_index('group').cumsum()
xmjlocator=MultipleLocator(1000)
xmnlocator=MultipleLocator(500)
ymjlocator=MultipleLocator(0.1)
ymnlocator=MultipleLocator(0.05)
yerr=(np.random.randn(1,8)/50).flatten()
markers=['v','o','s']
cols=['ACC','NMI','ARI']
colors=['b','g','y']
fig,axs=plt.subplots(1,2)
print(type(fig))
for col,mk,color in zip(cols,markers,colors):
axs[0].plot(df['group'],df[col],marker=mk,color=color)
axs[0].set_ylim([0.46,1.04])
axs[0].set_xlabel('x1')
axs[0].xaxis.set_minor_locator(xmnlocator)
axs[0].yaxis.set_minor_locator(ymnlocator)
axs[0].grid(which='major',axis='both',color='grey',linewidth=3)
axs[0].grid(which='minor',axis='both',color='grey',linewidth=1)
axs[0].spines['right'].set_visible(False)
axs[0].spines['left'].set_visible(False)
axs[0].spines['top'].set_visible(False)
axs[0].spines['bottom'].set_visible(False)
axs[0].tick_params(direction='out',length=0,width=4,colors='grey',
grid_color='grey',grid_alpha=.5,rotation=60,
axis='x')
axs[0].tick_params(direction='out',length=0,width=4,colors='grey',
grid_color='grey',grid_alpha=.5,
axis='y')
axs[0].tick_params(direction='in',length=0,width=1,colors='grey')
for col,mk,color in zip(cols,markers,colors):
axs[1].plot(df['group'],df[col],marker=mk,color=color)
axs[1].errorbar(df['group'],df[col],yerr=yerr,elinewidth=3,
color=color,fmt='_',capsize=4)
axs[1].set_ylim([0.46,1.04])
axs[1].set_xlabel('x2')
axs[1].xaxis.set_minor_locator(xmnlocator)
axs[1].yaxis.set_minor_locator(ymnlocator)
axs[1].grid(which='major',axis='both',color='grey',linewidth=3)
axs[1].grid(which='minor',axis='both',color='grey',linewidth=1)
axs[1].spines['right'].set_visible(False)
axs[1].spines['left'].set_visible(False)
axs[1].spines['top'].set_visible(False)
axs[1].spines['bottom'].set_visible(False)
axs[1].tick_params(direction='out',length=0,width=4,colors='grey',
grid_color='grey',grid_alpha=.5,rotation=60,
axis='x')
axs[1].tick_params(direction='out',length=0,width=4,colors='grey',
grid_color='grey',grid_alpha=.5,
axis='y')
axs[1].tick_params(direction='in',length=0,width=1,colors='grey')
plt.legend(labels=['ACC','NMI','ARI'],
bbox_to_anchor=(-0.6,-0.25,1,0.2),
loc='lower center',
mode='expand',
ncol=3,
columnspacing=1.0,
frameon=False)
plt.tight_layout()
plt.show()
|