[英]convert number pi into string "pi"
i'm working with a variable phi which takes some multiple of pi.我正在使用一个变量 phi,它需要一些 pi 的倍数。 For example i can set phi=2pi, which takes the value 6.283...
例如,我可以设置 phi=2pi,它的值为 6.283...
Then i would like to plot a string in my graph (i'm using matplotlib), which indicates the value i've given to phi, but written with the symbol pi.然后我想在我的图中绘制一个字符串(我使用的是 matplotlib),它表示我给 phi 的值,但用符号 pi 写。 In the case of phi=2pi, i would like to plot with latex '$ phi = 2\\pi $'.
在 phi=2pi 的情况下,我想用乳胶 '$ phi = 2\\pi $' 绘图。 The problem is that if i plot an f string, such as f'$ phi = {phi} $', then it takes the numerical value, instead of the symbol.
问题是,如果我绘制一个 f 字符串,例如 f'$ phi = {phi} $',则它采用数值,而不是符号。
How can i convert the numerical value to a string with the symbol pi?如何将数值转换为带有符号 pi 的字符串?
is it something similar you are looking for ?您正在寻找类似的东西吗?
import math
import matplotlib.pyplot as plt
pi=math.pi
phi='2/pi'
plt.plot(eval(phi),pi)
import matplotlib.pyplot as plt
import numpy as np
# b: blue, g: green, r: red, c: cyan, m: magenta, y: yellow, k: black, w: white
##################################################################################
# EQUATIONS
##################################################################################
constant=2
axis=np.linspace(-constant*np.pi, constant*np.pi,1000)
##################################################################################
# LABELING
##################################################################################
plt.plot(x, y)
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.title('Data_VIsualization')
##################################################################################
# PLOTTING
##################################################################################
plt.plot(x, y, color='y', linestyle='-')
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.