Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use special symbols when drawing by Python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how Python uses special symbols when drawing". Xiaobian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how Python uses special symbols when drawing" can help you solve the problem.

I. Background of the problem

How to use special symbols in the thesis? Here are the renderings and code

Complete Code:

from matplotlib import pyplotimport matplotlib.pyplot as pltfrom matplotlib.font_manager import FontPropertiesfrom matplotlib.ticker import MultipleLocator, FormatStrFormatter font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=15)import matplotlibimport numpy as npfrom mpl_toolkits.axes_grid1.inset_locator import inset_axesfrom mpl_toolkits.axes_grid1.inset_locator import mark_insetfrom matplotlib.patches import ConnectionPatch%matplotlib inlineplt.rcParams['figure.figsize'] = (8.0, 6.0) # set default size of plotsplt.rcParams['image.interpolation'] = 'nearest'plt.rcParams['image.cmap'] = 'gray'plt.rcParams['font.sans-serif']=['SimHei']plt.rcParams['axes.unicode_minus']=False #Set title size plt.rcParams <$'font.size'] = '16'#Solve partial overlap of graphics when drawing multiple images fig = plt.figure()matplotlib.rcParams.update ({'text.usetex': False,'font.family': 'stixgeneral','mathtext.fontset':'stix',})myfont = FontProperties (fname='/home/linuxidc/.local/share/fonts/Wen Quan Yi Zheng Hei. ttf')#Prepare data 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]#plot fig, ax = plot.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() #Make legend effective plt.title (r'$\alpha$ aaa')plt.xlabel ('X-axis', fontproperties=font_set) #X-axis label plt.ylabel ('Y-axis', fontproperties=font_set) #Y-axis label plt.grid ('linestyle ='-. ') plt.show () II. Notes

For example, you can add to the title, axis name (xlabel, ylabel), and label. Pay attention to using "r" after label equal sign, otherwise report error directly.

Take this as an example to replace

ax.plot (x, A, marker ='H ',linewidth=2,markersize=7,label=r'$\alpha $') III. Common special symbols and corresponding code symbols αβδ ε code $\alpha$\beta$\delta$\ell$\varepsilon$symbol Φγη π φ code $\phi $\gamma$\eta$\iota$\varphi$symbol λμπθρ code $\lambda$\mu$\pi$\theta$\rho$symbol στω θ code $\sigma$\tau$\omega $\xi$\Gamma $4. A Universal Method for Introducing Special Symbols

Then someone must ask, what if the characters to be expressed are very complex, such as those with formulas.

In fact, there's a universal way. MathType needs to be installed. This method is also applicable to Latex typesetting of foreign documents.

The three simple steps are as follows:

① Download mattype and associate word

② Type in your expression, edit and copy

③在word输入位置黏贴

只需关注最后一行的

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

去掉两边的"\["和"\]"

保留结果为

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

调用的时候两边加上$即可

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

效果如下:

关于"Python在画图时怎么使用特殊符号"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注行业资讯频道,小编每天都会为大家更新不同的知识点。

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report