python画矢量图_使用基于matplotlib的SciencePlots绘制精美图表

开源项目地址:https://github.com/garrettj403/SciencePlots

安装这个包,需要输入魔法:

pip install SciencePlots

例如绘制如下函数,导入matplotlib包:

import numpy as np import matplotlib.pyplot as plt

def model(x, p): return x ** (2 * p + 1) / (1 + x ** (2 * p))

x = np.linspace(0.75, 1.25, 201)

science样式,代码如下:

with plt.style.context([‘science’]): fig, ax = plt.subplots() for p in [10, 15, 20, 30, 50, 100]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig1.pdf’) fig.savefig(‘figures/fig1.jpg’, dpi=300)

science+ieee样式,代码如下:

with plt.style.context([‘science’, ‘ieee’]): fig, ax = plt.subplots() for p in [10, 20, 50]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig2.pdf’) fig.savefig(‘figures/fig2.jpg’, dpi=300)

science+scatter样式:

with plt.style.context([‘science’, ‘scatter’]): fig, ax = plt.subplots(figsize=(4,4)) ax.plot([-2, 2], [-2, 2], ‘k–‘) ax.fill_between([-2, 2], [-2.2, 1.8], [-1.8, 2.2], color=’dodgerblue’, alpha=0.2, lw=0) for i in range(7): x1 = np.random.normal(0, 0.5, 10) y1 = x1 + np.random.normal(0, 0.2, 10) ax.plot(x1, y1, label=r”$^#${}”.format(i+1)) ax.legend(title=’Sample’, loc=2) ax.set_xlabel(r”$log_{10}left(frac{L_mathrm{IR}}{mathrm{L}_odot}right)$”) ax.set_ylabel(r”$log_{10}left(frac{L_mathrm{6.2}}{mathrm{L}_odot}right)$”) ax.set_xlim([-2, 2]) ax.set_ylim([-2, 2]) fig.savefig(‘figures/fig3.pdf’) fig.savefig(‘figures/fig3.jpg’, dpi=300)

high-vis样式:

with plt.style.context([‘science’, ‘high-vis’]): fig, ax = plt.subplots() for p in [10, 15, 20, 30, 50, 100]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig4.pdf’) fig.savefig(‘figures/fig4.jpg’, dpi=300)

dark_background+science+high-vis样式:

with plt.style.context([‘dark_background’, ‘science’, ‘high-vis’]): fig, ax = plt.subplots() for p in [10, 15, 20, 30, 50, 100]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig5.pdf’) fig.savefig(‘figures/fig5.jpg’, dpi=300)

bright样式

with plt.style.context([‘science’, ‘bright’]): fig, ax = plt.subplots() for p in [5, 10, 15, 20, 30, 50, 100]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig6.pdf’) fig.savefig(‘figures/fig6.jpg’, dpi=300)

vibrant样式:

with plt.style.context([‘science’, ‘vibrant’]): fig, ax = plt.subplots() for p in [5, 10, 15, 20, 30, 50, 100]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig7.pdf’) fig.savefig(‘figures/fig7.jpg’, dpi=300)

muted样式:

with plt.style.context([‘science’, ‘muted’]): fig, ax = plt.subplots() for p in [5, 7, 10, 15, 20, 30, 38, 50, 100, 500]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’, fontsize=7) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig8.pdf’) fig.savefig(‘figures/fig8.jpg’, dpi=300)

retro样式:

with plt.style.context([‘science’, ‘retro’]): fig, ax = plt.subplots() for p in [10, 15, 20, 30, 50, 100]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig9.pdf’) fig.savefig(‘figures/fig9.jpg’, dpi=300)

science+notebook样式:

with plt.style.context([‘science’, ‘notebook’]): fig, ax = plt.subplots() for p in [10, 15, 20, 30, 50, 100]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig10.pdf’) fig.savefig(‘figures/fig10.jpg’, dpi=300)

science+grid样式,代码如下:

with plt.style.context([‘science’, ‘grid’]): fig, ax = plt.subplots() for p in [10, 15, 20, 30, 50, 100]: ax.plot(x, model(x, p), label=p) ax.legend(title=’Order’) ax.set(xlabel=’Voltage (mV)’) ax.set(ylabel=’Current ($mu$A)’) ax.autoscale(tight=True) fig.savefig(‘figures/fig11.pdf’) fig.savefig(‘figures/fig11.jpg’, dpi=300)

先不说了,广告时间又到了,现在植入广告:几个《传热学》相关的小程序总结如下,可在微信中点击体验:

有限元三角单元 格自动剖分

Delaunay三角化初体验

(理论戳这)

Contour等值线绘制

(理论戳这)

2D非稳态温度场有限元分析

1D稳态导热温度场求解

(源码戳这)

1D非稳态导热温度场求解程序

(源码戳这)

2D稳态导热温度场求解

(源码戳这)

普朗克黑体单色辐射力

《传热学》相关小程序演示动画如下(其中下图1D非稳态导热计算发散,调小时间步长后重新计算,结果收敛!):

点击播放 GIF 0.6M

《(计算)流体力学》中的几个小程序,可在微信中点击体验:

Blasius偏微分方程求解速度边界层

(理论这里)

理想流体在管道中的有势流动

(源码戳这)

涡量-流函数法求解顶驱方腔流动

(源码戳这)

SIMPLE算法求解顶驱方腔流动

(源码戳这)

Lattice Boltzmann Method计算绕流演示

(参考源码)

流体力学实验在线演示

进行演示

关于《(计算)流体力学》相关的几个小程序演示动画如下:

点击播放 GIF 0.5M

顺便,《(热工过程)自动控制》中关于PID控制器的仿真可点击此处体验:PID控制演示小程序,(PID控制相关视频见:基础/整定/重要补充)。动画如下:

点击播放 GIF 1.8M

文章知识点与官方知识档案匹配,可进一步学习相关知识Python入门技能树绘图库MatplotlibMatplotlib快速入门212711 人正在系统学习中 相关资源:口腔管理软件牙医管家口腔管理软件v3.11.0.16标准版_牙医管家…

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年10月22日
下一篇 2020年10月22日

相关推荐