python中pi_Python | 在图标签中添加Pi

python中pi

PI (π) is very often used greek mathematical letters and has a higher repetition in circular geometry and probability. In this article, we are going to add π using a command in matplotlib.

PI(π)是非常常用的希腊数学字母,并且在圆形几何形状和概率上具有较高的重复率。 在本文中,我们将使用matplotlib中的命令添加π

plt.text(3, 0.4, r'$\pi=100$')
#Adding π as text

Python | Adding Pi in Plot Label (1)
plt.title('Errorbar with 'r'$\pi=100$')
#Adding π in title of the figure

Python | Adding Pi in Plot Label (2)
plt.xlabel('Time ('r'$\pi=100)$')
#Adding π in title of the figure

Python | Adding Pi in Plot Label (3)
plt.ylabel('Variation ('r'$\pi=100)$')
#Adding π in title of the figure

Python | Adding Pi in Plot Label (4)

在情节标签中添加omega的Python代码 (Python code for adding omega in plot label)

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-3, 3)
y = np.tanh(x) + 0.1 * np.cos(5 * x)

# In text
plt.figure()
plt.plot(x, y, 'o', color='purple')
plt.title('Errorbar')
plt.text(2, 0.8, r'$\pi=100$', fontsize=14.0)
plt.grid()
plt.show()

# In title
plt.figure()
plt.plot(x, y, 'o', color='purple')
plt.title('Errorbar with 'r'$\pi=100$')
plt.grid()
plt.show()

# In x-axis label
plt.figure()
plt.plot(x, y, 'o', color='purple')
plt.xlabel('Time ('r'$\pi=100)$')
plt.grid()
plt.show()

# In y-axis label
plt.figure()
plt.plot(x, y, 'o', color='purple')
plt.ylabel('Variation ('r'$\pi=100)$')
plt.grid()
plt.show()

Output:

输出:

Output is as figure


翻译自: https://www.includehelp.com/python/adding-pi-in-plot-label.aspx

python中pi