python,matplotlib绘图文字text下标问题
在正常的一个绘图之后,我们可以得到
代码:
import numpy as np
import matplotlib.pyplot as pltxs1 = np.ones(100)
ys1 = range(1, 101)
zs1 = np.zeros(100)xs2 = np.ones(100) * 2
ys2 = range(1, 101)
zs2 = np.zeros(100)xs3 = np.ones(100) * 3
ys3 = range(1, 101)
zs3 = np.zeros(100)xs4 = np.ones(100) * 4
ys4 = range(1, 101)
zs4 = np.zeros(100)# Plot
# ax = plt.figure().add_subplot(projection='3d')from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure('figure10',dpi=500, figsize=(8,8))
ax = Axes3D(fig)ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([0.8, 1, 0.5, 1]))ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.plot(xs1, ys1, zs1, lw=2, color=[0.8, 0.33, 0])
ax.plot(xs2, ys2, zs2, lw=2, color=[0.33, 0.8, 0])
ax.plot(xs3, ys3, zs3, lw=2, color=[0, 0.5, 0.8])
ax.plot(xs4, ys4, zs4, lw=2, color=[0.8, 0.1, 0.5])
ax.set_xlabel("The Number of actuator")
ax.set_ylabel("Flight time")
ax.set_zlabel("The value of u_a")
# ax.set_zlabel("The value of $u_a$")
# plt.legend(labels=['$u_{a1}$','$u_{a2}$','$u_{a3}$','$u_{a4}$'], loc='best')
plt.legend(labels=['u_a1','u_a2','u_a3','u_a4'], loc='best')
plt.rcParams['font.sans-serif'] = ['Arial']
plt.rcParams['axes.unicode_minus'] = False
ax.set_title("Addective fault simulation")
ax.set(xlim=[1, 4], ylim=[0, 100], zlim=[-0.5, 0.3])
ax.view_init(32, -32)
plt.xticks([1,2,3,4])
# plt.show()
plt.savefig('./fig/figure10(a).png')
plt.close()
绘图结果:

问题是,我们希望下标部分是真实存在的,那么我们可以使用以下代码,如果是下标只有一个字母或数字,只需要在这个部分的两侧添加$ $即可,如果涉及到多个字符,那么只需把期望的下标部分加上{}。
ax.set_zlabel("The value of $u_a$")
plt.legend(labels=['$u_{a1}$','$u_{a2}$','$u_{a3}$','$u_{a4}$'], loc='best')
效果如下:

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
