传奇的格式用Matplotlib中的方程式
我们如何在Pyplot图的传说中显示一个方程式? 下面的示例代码:
fig = plt.figure(figsize=(5, 3), dpi=my_dpi)
ax = fig.add_subplot(111)
a = 2.0
b = 3.0
xdata = np.arange(6)
ydata = a*np.power(xdata,b)
# I want the b variable in the equation below to be a subscript.
label = '${0:.2f} x^{{0:.2f}}$'.format(a,b)
plt.plot(xdata,ydata, alpha = 0.5, label = label)
plt.legend()
plt.show()
How do we show an equation in the legend of a pyplot plot?
Sample code below:
fig = plt.figure(figsize=(5, 3), dpi=my_dpi)
ax = fig.add_subplot(111)
a = 2.0
b = 3.0
xdata = np.arange(6)
ydata = a*np.power(xdata,b)
# I want the b variable in the equation below to be a subscript.
label = '${0:.2f} x^{{0:.2f}}
.format(a,b)
plt.plot(xdata,ydata, alpha = 0.5, label = label)
plt.legend()
plt.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种可能的解决方案:首先将浮子格式化为字符串,而不是将字符串放在一起:
One possible solution: first format your float to strings, than put the strings together: