SciencePlots Matplotlib-style library for scientific plotting

foreword

  • 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 SciencePlotspip 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'] = False

import 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()

insert image description here

Official document display

  • More theme collocations can be found here .
  • plt.style.use(['science'])
    Please add a picture description
  • plt.style.use(['science', 'ieee'])
    Please add a picture description
  • plt.style.use(['science', 'notebook'])
    Please add a picture description
  • plt.style.use(['science', 'scatter'])
    Please add a picture description
  • plt.style.use(['dark_background', 'science', 'high-vis'])
    Please add a picture description
  • plt.style.use(['science', 'bright'])
    Please add a picture description
  • plt.style.use(['science', 'vibrant'])
    Please add a picture description
  • plt.style.use(['science', 'muted'])
    Please add a picture description
  • plt.style.use(['science', 'retro'])
    Please add a picture description
  • plt.style.use(['science', 'grid'])
    Please add a picture description
  • plt.style.use(['science', 'high-contrast'])
    Please add a picture description
  • plt.style.use(['science', 'light'])
    Please add a picture description
  • plt.style.use(['science', 'no-latex', 'cjk-tc-font'])
    Please add a picture description
  • plt.style.use(['science', 'no-latex', 'cjk-sc-font'])
    Please add a picture description
  • plt.style.use(['science', 'no-latex', 'cjk-jp-font'])
    Please add a picture description
  • plt.style.use(['science', 'no-latex', 'cjk-kr-font'])
    Please add a picture description
  • plt.style.use(['science', 'russian-font'])
    Please add a picture description
  • plt.style.use(['science', 'turkish-font'])
    Please add a picture description

Guess you like

Origin blog.csdn.net/qq_20144897/article/details/130461520