欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在Matplotlib圖中插入LaTex公式實(shí)例

 更新時(shí)間:2020年04月17日 09:42:42   作者:今晚打佬虎  
這篇文章主要介紹了在Matplotlib圖中插入LaTex公式實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

Matplotlib可以無縫的處理LaTex字體,在圖中加入數(shù)學(xué)公式

from matplotlib.patches import Polygon
import matplotlib.pyplot as plt
import numpy as np
# 定義一個(gè)求積分的函數(shù)
def func(x):
 return 0.3* (x**2) + (0.1*x) + 1
# 定義積分區(qū)間
a, b = 1,2
x = np.linspace(0,3)
y = func(x)
# 繪制曲線
fig, ax = plt.subplots(figsize=(14,8))
plt.plot(x, y, 'g')
plt.ylim(ymin=0)

# 使用Polygon生成陰影部分
Ix = np.linspace(a, b)
Iy = func(Ix)
verts = [(a, 0)] + list(zip(Ix, Iy)) + [(b, 0)]
ploy = Polygon(verts, facecolor = '0.7', edgecolor='0.5')
ax.add_patch(ploy)

# 添加數(shù)學(xué)公式和坐標(biāo)軸標(biāo)簽
# r" "中間為LaTex語法表示的公式
plt.text(0.5 * (a+b), 1, r"$\int_a^b f(x)\mathrmvvxyksv9kdx$",
  horizontalalignment='center', fontsize=20)
# 前兩個(gè)參數(shù)是放置文本的坐標(biāo)
plt.figtext(0.9, 0.075,'$x$')
plt.figtext(0.075,0.9,'$f(x)$' )

ax.set_xticks((a,b))
ax.set_xticklabels(('$a$','b'))
ax.set_yticks((func(a), func(b)))
ax.set_yticklabels(('f(a)','f(b)'))
plt.grid(True)
plt.show()

補(bǔ)充知識(shí):matplotlib用tex寫數(shù)學(xué)公式

廢話不多說,直接看代碼吧!

import numpy as np
import matplotlib
matplotlib.rcParams['text.usetex'] = True
import matplotlib.pyplot as plt


t = np.linspace(0.0, 1.0, 100)
s = np.cos(4 * np.pi * t) + 2

fig, ax = plt.subplots(figsize=(6, 4), tight_layout=True)
ax.plot(t, s)

ax.set_xlabel(r'\textbf{time (s)}')
ax.set_ylabel('\\textit{Velocity (\N{DEGREE SIGN}/sec)}', fontsize=16)
ax.set_title(r'\TeX\ is Number $\displaystyle\sum_{n=1}^\infty'
    r'\frac{-e^{i\pi}}{2^n}$!', fontsize=16, color='r')
plt.show()

以上這篇在Matplotlib圖中插入LaTex公式實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論