Python-matplotlib exponent representation in title when drawing graphs

1.Example 

2.Core code

# 修改横轴的刻度
# 生成刻度的位置和标签
total_steps = 1000000  # 总共100万步
num_segments = 10  # 分成10段
segment_length = total_steps // num_segments  # 每段的步数

# 生成刻度的位置
custom_ticks = np.arange(0, total_steps + 1, segment_length)
# 生成刻度的标签
custom_labels = [f'{i // 10000}' for i in custom_ticks]

# 设置横轴刻度
plt.xticks(ticks=custom_ticks, labels=custom_labels)

# 标签
# plt.xlabel('Step(\u00D710000)')                # Step(x10000)
# plt.xlabel('Step'+'$\mathit{/10}^{4}$')        # Step/10^4
# plt.xlabel('Step'+'$\mathit{\u00D710}^{4}$')   # Stepx10^4
plt.xlabel('Step'+'$\mathit{(\u00D710}^{4})$')   # Step(x10^4)
plt.ylabel('Reward')

# 显示图形
plt.show()

2.1 plt.xlabel('Step(\u00D710000)')

\u00D7 represents the multiplication sign (x)

2.2 plt.xlabel('Step'+'$\mathit{/10}^{4}$')

With exponential form

2.3 plt.xlabel('Step'+'$\mathit{\u00D710}^{4}$')

With the multiplication sign and exponential form

2.4 plt.xlabel('Step'+'$\mathit{(\u00D710}^{4})$')

There are multiplication signs and exponent forms, as well as parentheses

Reference blog:  https://blog.csdn.net/qq_41721951/article/details/107394178

Guess you like

Origin blog.csdn.net/aaaccc444/article/details/132570093