網(wǎng)站首頁(yè) 編程語(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
相關(guān)推薦
- 2023-07-26 TypeScript中的類型聲明declare
- 2022-02-22 用Go+Redis實(shí)現(xiàn)分布式鎖的示例代碼_Golang
- 2022-04-20 Python設(shè)計(jì)模式中的結(jié)構(gòu)型適配器模式_python
- 2023-08-15 解決:Unexpected ‘debugger‘ statement.eslint(no-debug
- 2022-01-30 axios自帶的上傳進(jìn)度回調(diào)函數(shù)
- 2022-01-18 npm ERR! code ENOENT npm ERR! syscall open npm ERR
- 2022-03-28 C語(yǔ)言實(shí)現(xiàn)紅黑樹(shù)詳細(xì)步驟+代碼_C 語(yǔ)言
- 2023-06-21 詳解C#中委托的概念與使用_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支