当前位置:网站首页>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
边栏推荐
- MapReduce compression
- Construction and traversal of binary tree
- [Niuke challenge 47] C. conditions (BitSet acceleration Floyd)
- Embedded related surface (I)
- /etc/shadow可以破解吗?
- Swagger2 自定义参数注解如何不显示
- 24. Exchange the nodes in the linked list (linked list)
- 206. Reverse linked list (linked list)
- Precautions for latex formula
- Let the LAN group use the remote device
猜你喜欢
![[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)

/etc/shadow可以破解吗?

Introduction to wechat applet, development history, advantages of applet, application account, development tools, initial knowledge of wxml file and wxss file

【leetcode】102. Sequence traversal of binary tree

VIM + ctags + cscope development environment construction guide

Charles function introduction and use tutorial

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

高价买来的课程,公开了!phper资料分享

MapReduce compression

ID number verification system based on visual structure - Raspberry implementation
随机推荐
Deploy jar package
Learning Notes 6 - Summary of several deep learning convolutional neural networks
Introduction to data analysis 𞓜 kaggle Titanic mission (III) - > explore data analysis
SQL Server cursor circular table data
【leetcode】199. Right view of binary tree
202、快乐数
Linked list intersection (linked list)
定义链表(链表)
Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"
Manjaro installation and configuration (vscode, wechat, beautification, input method)
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)
The difference between restful and soap
What are Jerry's usual program exceptions? [chapter]
比深度学习更值得信赖的模型ART
SSH uses private key to connect to server without key
Code implementation of general bubbling, selection, insertion, hill and quick sorting
Jerry's users how to handle events in the simplest way [chapter]
997. Square of ordered array (array)
Precautions for latex formula
Chapter 120 SQL function round