ignore chinese code question

master
李中梁 2018-01-02 19:57:38 +08:00 committed by GitHub
parent 5f3faefe34
commit 83e47e3173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -12,8 +12,8 @@ import matplotlib.font_manager as fm
from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d import Axes3D
# 解决中文乱码问题 # 解决中文乱码问题
myfont = fm.FontProperties(fname="/Library/Fonts/Songti.ttc", size=14) # myfont = fm.FontProperties(fname="/Library/Fonts/Songti.ttc", size=14)
matplotlib.rcParams["axes.unicode_minus"] = False # matplotlib.rcParams["axes.unicode_minus"] = False
def simple_plot(): def simple_plot():
@ -26,16 +26,19 @@ def simple_plot():
# 生成画布,并设定标题 # 生成画布,并设定标题
plt.figure(figsize=(8, 6), dpi=80) plt.figure(figsize=(8, 6), dpi=80)
plt.title("简单曲线图", fontproperties=myfont) # plt.title("简单曲线图", fontproperties=myfont)
plt.title("简单曲线图")
plt.grid(True) plt.grid(True)
# 设置X轴 # 设置X轴
plt.xlabel("X轴", fontproperties=myfont) # plt.xlabel("X轴", fontproperties=myfont)
plt.xlabel("X轴")
plt.xlim(-4.0, 4.0) plt.xlim(-4.0, 4.0)
plt.xticks(np.linspace(-4, 4, 9, endpoint=True)) plt.xticks(np.linspace(-4, 4, 9, endpoint=True))
# 设置Y轴 # 设置Y轴
plt.ylabel("Y轴", fontproperties=myfont) # plt.ylabel("Y轴", fontproperties=myfont)
plt.ylabel("Y轴")
plt.ylim(-1.0, 1.0) plt.ylim(-1.0, 1.0)
plt.yticks(np.linspace(-1, 1, 9, endpoint=True)) plt.yticks(np.linspace(-1, 1, 9, endpoint=True))
@ -44,7 +47,7 @@ def simple_plot():
plt.plot(x, y_sin, "g-", linewidth=2.0, label="sin示例") plt.plot(x, y_sin, "g-", linewidth=2.0, label="sin示例")
# 设置图例位置,loc可以为[upper, lower, left, right, center] # 设置图例位置,loc可以为[upper, lower, left, right, center]
plt.legend(loc="upper left", prop=myfont, shadow=True) # plt.legend(loc="upper left", prop=myfont, shadow=True)
# 图形显示 # 图形显示
plt.show() plt.show()
@ -500,3 +503,5 @@ def three_dimension_bar():
plt.show() plt.show()
return return
# three_dimension_bar() # three_dimension_bar()
simple_plot()