日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

Python在畫圖時(shí)使用特殊符號(hào)的方法總結(jié)_python

作者:sinysama ? 更新時(shí)間: 2022-06-23 編程語(yǔ)言

本文總結(jié)了python畫圖中使用各種特殊符號(hào)方式

一、問(wèn)題背景

在論文中,如何使用特殊符號(hào)進(jìn)行表示?這里給出效果圖和代碼

完整代碼:

from matplotlib import pyplot
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
from matplotlib.ticker import MultipleLocator, FormatStrFormatter 
font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=15)
import matplotlib
import numpy as np
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
from matplotlib.patches import ConnectionPatch
%matplotlib inline

plt.rcParams['figure.figsize'] = (8.0, 6.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False     
# 設(shè)置標(biāo)題大小
plt.rcParams['font.size'] = '16'
#解決畫多幅圖時(shí)出現(xiàn)圖形部分重疊
fig = plt.figure()
matplotlib.rcParams.update(
{
'text.usetex': False,
'font.family': 'stixgeneral',
'mathtext.fontset': 'stix',
}
)
myfont = FontProperties(fname='/home/linuxidc/.local/share/fonts/文泉驛正黑.ttf')

#準(zhǔn)備數(shù)據(jù)
x = range(0,31,2)

A=[0.2204262385828951,0.30839304560351055,0.4176158354528364,0.5689115113547377,0.7132088021728286,0.8170438670019559,0.874248496993988,0.8998229892687244,0.9022254048694502,0.9059819476369345,0.9094392004441977,0.9087585175336547,0.9070491438736936,0.9061997894620201,0.9090201312423535,0.905820399113082]
B=[0.16086354829781346,0.24623673832139087,0.37067344907663385,0.5243875153820338,0.6455296269608115,0.7488125174629785,0.8000445335114674,0.8252572187188848,0.8275862068965517,0.8340528115714526,0.8372015546918379,0.837903717245582,0.8390037802979764,0.8358911851072082,0.8319986653319986,0.8359756097560975]
C=[0.18306116800442845,0.2870632672332389,0.4144089350879133,0.5520192415258978,0.7109362008757829,0.8372170997485331,0.9124159429971054,0.9341066489655936,0.946792993279718,0.9503133935078769,0.9521488062187674,0.952635311063099,0.9535668223259951,0.9552372984652889,0.9439895451006562,0.9501552106430155]


#繪圖
fig, ax = plt.subplots(1, 1)

ax.plot(x, A, marker='H',linewidth=2,markersize=7,label=r'$\alpha$')
ax.plot(x, B, marker='s',linewidth=2,markersize=7,label=r'$\ell$')
ax.plot(x, C, marker='D',linewidth=2,markersize=7,label=r'$\mu$')
plt.grid(linestyle='-.')  
plt.grid(True)
y_major_locator=MultipleLocator(0.1)
x_major_locator=MultipleLocator(2)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.ylim(0,1.0)
plt.xlim(0,31)

plt.legend()  # 讓圖例生效
plt.title(r'$\alpha$ aaa')
plt.xlabel('X-axis',fontproperties=font_set) #X軸標(biāo)簽
plt.ylabel("Y-axis",fontproperties=font_set) #Y軸標(biāo)簽

plt.grid(linestyle='-.')  

plt.show()

二、注意事項(xiàng)

應(yīng)用例子,可以在標(biāo)題(title)、坐標(biāo)軸名(xlabel、ylabel)、標(biāo)注標(biāo)簽處(label)增加。注意使用label等號(hào)后面使用“r”,否則直接報(bào)錯(cuò)。
以此為例進(jìn)行替換即可↓

ax.plot(x, A, marker='H',linewidth=2,markersize=7,label=r'$\alpha$')

三、常見(jiàn)特殊符號(hào)及對(duì)應(yīng)代碼

符號(hào) α β δ ? ε
代碼 $\alpha$ $\beta$ $\delta$ $\ell$ $\varepsilon$
符號(hào) Φ γ η ι φ
代碼 $\phi $ $\gamma$ $\eta$ $\iota$ $\varphi$
符號(hào) λ μ π θ ρ
代碼 $\lambda$ $\mu$ $\pi$ $\theta$ $\rho$
符號(hào) σ τ ω ξ Γ
代碼 $\sigma$ $\tau$ $\omega$ $\xi$ $\Gamma$

四、引入特殊符號(hào)的萬(wàn)能方法

那么肯定有人要問(wèn)了,如果要表達(dá)的字符很復(fù)雜怎么辦,比如帶公式的。

事實(shí)上,這里有個(gè)通用方式。但是需要安裝MathType。該方法在外文文獻(xiàn)的Latex排版中也同樣適用。

簡(jiǎn)單三步如下,:

①下載mathtype,并關(guān)聯(lián)word

②打入你的表達(dá)式,編輯并復(fù)制

③在word輸入位置黏貼

只需關(guān)注最后一行的

\[\int {\frac{{n!}}{{r!\left( {n - r} \right)!}}} \]

去掉兩邊的“\[”和“\]”

保留結(jié)果為

\int {\frac{{n!}}{{r!\left( {n - r} \right)!}}}

調(diào)用的時(shí)候兩邊加上$即可

ax.plot(x, C, marker='D',linewidth=2,markersize=7,label=r'$\int {\frac{{n!}}{{r!\left( {n - r} \right)!}}} $')

效果如下:

原文鏈接:https://blog.csdn.net/QAQIknow/article/details/124390075

欄目分類
最近更新