Python在畫圖時(shí)使用特殊符號(hào)的方法總結(jié)
本文總結(jié)了python畫圖中使用各種特殊符號(hào)方式
一、問題背景
在論文中,如何使用特殊符號(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$')
三、常見特殊符號(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)的萬能方法
那么肯定有人要問了,如果要表達(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)!}}} $')
效果如下:
到此這篇關(guān)于Python在畫圖時(shí)使用特殊符號(hào)的方法總結(jié)的文章就介紹到這了,更多相關(guān)Python特殊符號(hào)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解Python調(diào)用華為API實(shí)現(xiàn)圖像標(biāo)簽
華為云圖像標(biāo)簽可識(shí)別上千種通用物體以及數(shù)百種場(chǎng)景標(biāo)簽,一個(gè)圖像可包含多個(gè)標(biāo)簽內(nèi)容,語義內(nèi)容非常豐富。本文將通過Python調(diào)用華為API實(shí)現(xiàn)圖像標(biāo)簽,需要的可以參考一下2022-04-04python數(shù)據(jù)處理67個(gè)pandas函數(shù)總結(jié)看完就用
這篇文章主要介紹了python數(shù)據(jù)處理67個(gè)pandas函數(shù)的梳理總結(jié),看完就可以去用了,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-11-11Jupyter Notebook遠(yuǎn)程登錄及密碼設(shè)置操作
今天小編就為大家分享一篇Jupyter Notebook遠(yuǎn)程登錄及密碼設(shè)置操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-04-04基于Python實(shí)現(xiàn)一個(gè)簡(jiǎn)單的敏感詞過濾功能
這篇文章主要介紹了Python實(shí)現(xiàn)敏感詞過濾功能的示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)我們學(xué)習(xí)python有定的幫助,感興趣的小伙伴們可以參考一下2023-06-06ubuntu 18.04 安裝opencv3.4.5的教程(圖解)
這篇文章主要介紹了ubuntu 18.04 安裝opencv3.4.5的教程,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11