Code
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set() #设置seaborn默认格式
np.random.seed(0) #设置随机种子数
# from matplotlib.font_manager import FontProperties #显示中文,并指定字体
# myfont=FontProperties(fname=r'C:/Windows/Fonts/simhei.ttf',size=14)
# sns.set(font=myfont.get_name())
plt.rcParams['axes.unicode_minus']=False #显示负号
mean = 0
std = 20
N = 10000
x = np.random.randn(N) * std + mean
plt.rcParams['figure.figsize'] = (13, 5) #设定图片大小
f = plt.figure() #确定画布
f.add_subplot(1,2,1)
sns.distplot(x, kde=False) #绘制频数直方图
plt.ylabel("个数", fontsize=16)
plt.xticks(fontsize=16) #设置x轴刻度值的字体大小
plt.yticks(fontsize=16) #设置y轴刻度值的字体大小
plt.title("(n=%s,T=%sk)"%(N,std), fontsize=20) #设置子图标题
# f.add_subplot(1,2,2)
# sns.distplot(x) #绘制密度直方图
# plt.ylabel("密度", fontsize=16)
# plt.xticks(fontsize=16) #设置x轴刻度值的字体大小
# plt.yticks(fontsize=16) #设置y轴刻度值的字体大小
# plt.title("(b)", fontsize=20) #设置子图标题
# plt.subplots_adjust(wspace=0.3) #调整两幅子图的间距
plt.savefig("./tongji2.jpg")
plt.show()/var/folders/nl/_kfvn24j60j8_q_3kd0njl3h0000gn/T/ipykernel_35616/82418955.py:22: UserWarning:
`distplot` is a deprecated function and will be removed in seaborn v0.14.0.
Please adapt your code to use either `displot` (a figure-level function with
similar flexibility) or `histplot` (an axes-level function for histograms).
For a guide to updating your code to use the new functions, please see
https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751
sns.distplot(x, kde=False) #绘制频数直方图
/var/folders/nl/_kfvn24j60j8_q_3kd0njl3h0000gn/T/ipykernel_35616/82418955.py:36: UserWarning: Glyph 20010 (\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from current font.
plt.savefig("./tongji2.jpg")
/var/folders/nl/_kfvn24j60j8_q_3kd0njl3h0000gn/T/ipykernel_35616/82418955.py:36: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from current font.
plt.savefig("./tongji2.jpg")
/Users/yefan/.pyenv/versions/3.11.4/lib/python3.11/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 20010 (\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
/Users/yefan/.pyenv/versions/3.11.4/lib/python3.11/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
