SciencePlotsPackages are matplotlibtheme extension libraries for packages, so we must have both SciencePlotspackages and matplotlibpackages. SciencePlotspackage [official address]. (https://github.com/garrettj403/SciencePlots)
pip install SciencePlots,pip install matplotlib
Latex support is also required to use this package, Latex download link . Chinese fonts need Noto Serif SCsupport, download link . After installing the font, you need to matplotlibupdate the font cache of the package. Taking the win system as an example, delete C:\Users\lenovo\.matplotlibthe folder and execute it again import matplotlib as mplto update the font library.
The Chinese font is used in the official document plt.style.use(['science', 'no-latex', 'cjk-sc-font']). I installed it 'cjk-sc-font'(that is, 'Noto Serif SC'the font) but still get an error. I plt.rcParams['font.sans-serif']=['Noto Serif SC']can achieve the same effect by using it. If anyone knows how to solve it, please private message me to modify the tutorial.
drawing
#加载包import numpy as np
import pandas as pd
from plotnine import*import seaborn as sns
from scipy import stats
import matplotlib as mpl
import matplotlib.pyplot as plt
# 中文显示问题
plt.rcParams['font.sans-serif']=['Noto Serif SC']
plt.rcParams['axes.unicode_minus']=Falseimport scienceplots
plt.style.use(['science','ieee','notebook'])# notebook嵌入图片%matplotlib inline
# 提高分辨率%config InlineBackend.figure_format='retina'# 忽略警告import warnings
warnings.filterwarnings('ignore')
x = np.arange(1,10,0.5)
y_1 = x *2+4+ x **2
y_2 = x *0.5+3+ x **1.5
y_3 = x *3.5+2+ x **3
plt.figure()
plt.plot(x, y_1)
plt.plot(x, y_2)
plt.plot(x, y_3)
plt.xlabel('时间(s)')
plt.ylabel('电力情况(k)')
plt.show()