使用matplotlib绘制带置信区间的折线图

#轮廓系数
import matplotlib
import matplotlib.pyplot as plt
# 处理乱码
%matplotlib inline
plt.figure(figsize=(8,4))
plt.style.use("ggplot")
# 常用风格:
# ['bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark-palette', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'seaborn', 'Solarize_Light2', 'tableau-colorblind10', '_classic_test']
plt.grid(True,linestyle="--",color="gray",linewidth="0.5",axis="both")
# fonts = fm.FontProperties(fname=r'C:\Windows\Fonts\simkai.ttf')
matplotlib.rcParams['font.sans-serif'] = 'SimHei, Times New Roman'  # 用黑体显示中文
matplotlib.rcParams['axes.unicode_minus']=False

x = [2,3,4,5,6,7,8,9,10]
y1 = [0.470436153, 0.430537331, 0.408863754, 0.400214607, 0.040786814, 0.400032794, 0.302064969, 0.213973414,0.073649858625158]


# "r" 表示红色,ms用来设置*的大小
plt.plot(x, y1, "r", ms=10)
plt.fill_between(x,np.array(y1)-0.1, np.array(y1)+0.1,interpolate=True, alpha=0.5)


plt.xticks(rotation=0) #设置倾斜度
plt.xlabel("簇的数量",fontsize=12)
plt.ylabel("轮廓系数",fontsize=12)
# plt.legend(loc="best")

plt.savefig("轮廓系数.png",bbox_inches='tight',dpi=400)
plt.show()

你可能感兴趣的:(matplotlib)