当前位置:网站首页>Visual solutions to common problems (VIII) mathematical formulas
Visual solutions to common problems (VIII) mathematical formulas
2022-04-23 10:53:00 【The big pig of the little pig family】
The mathematical formula
One . Preface
When visualizing , We often encounter the situation of drawing some formulas , These formulas appear in the legend 、 Axis labels and titles , The problem is that if you use ordinary strings to write formulas, the display effect is very poor , The comparison is as follows :

You can see that the legend on the left is irregular and unsightly , But with the LaTeX The formula shows that the effect has been greatly improved .
Two . Solution
Matplotlib Internal LaTeX Parser and layout engine . So you can use it directly LaTeX Write the formula .
Draw two functions as an example :
- ∑ 1 n x + 3 \sum_{1}^{n} x+3 ∑1nx+3
- sin x cos x \sin x \cos x sinxcosx
The complete procedure is as follows :
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei'] # Settings support Chinese
plt.rcParams['axes.unicode_minus'] = False # Set up - Number
# obtain X and Y
n = 15
x_1 = np.arange(1, n+1, 1)
y_1 = np.cumsum(x_1) + 3
x_2 = np.arange(0, 2*np.pi, np.pi/36)
y_2 = np.sin(x_2) * np.cos(x_2)
figure, ax = plt.subplots(1, 2)
# mapping
ax[0].plot(x_1, y_1, lw=3, color='k', label='$\sum_{1}^{n}x+3}$')
ax[0].set_title('$\sum_{1}^{n}x+3}$ function ', fontsize=20)
ax[0].set_xlabel("X", fontsize=15)
ax[0].set_ylabel('$\sum_{1}^{n}x+3}$ function ', fontsize=15)
ax[0].legend()
ax[1].plot(x_2, y_2, lw=3, color='r', label='$\sin x \cos x$')
ax[1].set_title('$\sin x \cos x$ function ', fontsize=20)
ax[1].set_xlabel("X", fontsize=15)
ax[1].set_ylabel('$\sin x \cos x$ function ', fontsize=15)
ax[1].legend()
plt.show()
2.1 The legend uses a mathematical formula

2.2 The title uses mathematical formulas

2.3 Axis labels use mathematical formulas

3、 ... and . Reference resources
版权声明
本文为[The big pig of the little pig family]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230617063531.html
边栏推荐
- Chapter 120 SQL function round
- RESTful和SOAP的区别
- Gets the current time in character format
- Kaggle - real battle of house price prediction
- Resolution and size of mainstream mobile phones
- 203、移出链表元素(链表)
- MySQL how to merge the same data in the same table
- 解决方案架构师的小锦囊 - 架构图的 5 种类型
- Jerry's users how to handle events in the simplest way [chapter]
- Six practices of Windows operating system security attack and defense
猜你喜欢

mysql同一个表中相同数据怎么合并

MapReduce compression

How can swagger2 custom parameter annotations not be displayed

【leetcode】107. Sequence traversal of binary tree II

【leetcode】107.二叉树的层序遍历II

Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
![[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)](/img/e4/3c47edbc3241ba86f10a1ac8a963fd.png)
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)

景联文科技—专业数据标注公司和智能数据标注平台

Chapter 120 SQL function round

Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
随机推荐
Define linked list (linked list)
A diary of dishes | 238 Product of arrays other than itself
景联文科技—专业数据标注公司和智能数据标注平台
全栈交叉编译X86完成过程经验分享
C#和数据库连接中类的问题
最强日期正则表达式
Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"
Pycharm
精彩回顾|「源」来如此 第六期 - 开源经济与产业投资
HuggingFace
定义链表(链表)
比深度学习更值得信赖的模型ART
SQL Server 递归查询上下级
RESTful和SOAP的区别
Notes on concurrent programming of vegetables (V) thread safety and lock solution
How can swagger2 custom parameter annotations not be displayed
Special members and magic methods
Latex usage
Problems of class in C # and database connection
Let the LAN group use the remote device