前
#-*- coding: utf-8 -*-
import numpy as np
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
font = FontProperties(fname=r"C:\Windows\Fonts\simsun.ttc", size=14)
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
def Plot(column,mean_1,mean_2,mean_3,number1,number2,string):
x_zhou = np.array(range (column))
x_zhou1 = np.linspace(0,11,10)
zhibiao = np.zeros(10)
#for i in range(10):
#zhibiao.append(0.2)
plt.figure()
plt.title('舆情平衡态观点分布与预期观点引导分布相对距离图')
#plt.plot(x_zhou,mean_s)
#plt.plot(x_zhou,mean_e)
plt.plot(x_zhou,mean_1)
plt.plot(x_zhou,mean_2)
plt.plot(x_zhou,mean_3)
plt.plot(x_zhou1,zhibiao+0.2)
#plt.plot(x_zhou,mean_4)
#plt.plot(x_zhou,mean_i_pos)
#plt.plot(x_zhou,mean_r)
#plt1 = plt.twinx()
plt.ylim((0,1))
plt.xlim((0,column))
plt.xticks(np.linspace(0, column, column+1))#构建等差数列
plt.yticks(np.linspace(0, 1, 11))
plt.legend(labels = ['禁言前','禁言'+str(number1)+'个点','禁言'+str(number2)+'个点'], prop=font,loc = 'best')
plt.xlabel('时步',fontproperties=font)
plt.ylabel(string,fontproperties=font)
#plt1.ylabel(string,fontproperties=font)
plt.grid()
plt.show()
后
#-*- coding: utf-8 -*-
import numpy as np
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
font = FontProperties(fname=r"C:\Windows\Fonts\simsun.ttc", size=14)
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
def Plot(column,mean_1,mean_2,mean_3,number1,number2):
x_zhou = np.array(range (column))
x_zhou1 = np.linspace(0,11,10)
zhibiao = np.zeros(10)
#for i in range(10):
#zhibiao.append(0.2)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x_zhou1,zhibiao+0.2,'r')
ax1.set_ylabel('平均负面观点传播密度')
ax1.set_title("舆情平衡态观点分布与预期观点分布")
ax1.legend(labels = ['≤0.2满足指标'], prop=font,loc = 2)
ax1.set_xlabel('时步')
plt.ylim((0,1))
plt.xlim((0,column))
plt.xticks(np.linspace(0, column, column+1))#构建等差数列
plt.yticks(np.linspace(0, 1, 11))
#plt.title('舆情平衡态观点分布与预期观点引导分布相对距离图')
ax2 = ax1.twinx()
ax2.plot(x_zhou,mean_1)
ax2.plot(x_zhou,mean_2)
ax2.plot(x_zhou, mean_3)
ax2.set_ylabel('相对距离')
ax2.set_xlabel('时步')
#plt.plot(x_zhou,mean_1)
#plt.plot(x_zhou,mean_2)
#plt.plot(x_zhou,mean_3)
#plt.plot(x_zhou1,zhibiao+0.2)
#plt.plot(x_zhou,mean_4)
#plt.plot(x_zhou,mean_i_pos)
#plt.plot(x_zhou,mean_r)
#plt1 = plt.twinx()
plt.ylim((0,1))
plt.xlim((0,column))
plt.xticks(np.linspace(0, column, column+1))#构建等差数列
plt.yticks(np.linspace(0, 1, 11))
ax2.legend(labels = ['禁言前','禁言'+str(number1)+'个点','禁言'+str(number2)+'个点'], prop=font,loc = 'best')
#plt.xlabel('时步',fontproperties=font)
#plt.ylabel('',fontproperties=font)
#plt1.ylabel(string,fontproperties=font)
plt.grid()
plt.show()