如何在 matplotlib 中使用 set_yticklabels 在标签中输入幂
How to input exponentiation in label using set_yticklabels in matplotlib
你好我想将刻度标签设置为一些数字乘以 10 的 6 次方。问题是我不知道如何让 matplotlib 很好地显示它。我执行以下操作:
ax.set_yticks([1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000])
ax.set_yticklabels([ '1.0*10^6', '1.2*10^6', '1.4*10^6', '1.6*10^6', '1.8*10^6', '2.0*10^6', '2.2*10^6', '2.4*10^6' ], rotation=0, ha='center', va='top')
上面的效果不是我想看到的。我得到了:
但我想要以下内容:
我怎样才能做到这一点?
您需要使用数学符号。这与在 Latex 中一样,通过用 $
将数学表达式括起来。详细解释 here.
对于您的情况,您可以将字符串写为:
ax.set_yticklabels([ '.0 \cdot 10^6$', '.2 \cdot 10^6$',...], rotation=0, ha='center', va='top')
您可以在字符串中使用 unicode:
ax.set_yticklabels([ '1.0∙10⁶', '1.2∙10⁶', '1.4∙10⁶', '1.6∙10⁶', '1.8∙10⁶', '2.0∙10⁶', '2.2∙10⁶', '2.4∙10⁶' ], rotation=0, ha='center', va='top')
你好我想将刻度标签设置为一些数字乘以 10 的 6 次方。问题是我不知道如何让 matplotlib 很好地显示它。我执行以下操作:
ax.set_yticks([1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000])
ax.set_yticklabels([ '1.0*10^6', '1.2*10^6', '1.4*10^6', '1.6*10^6', '1.8*10^6', '2.0*10^6', '2.2*10^6', '2.4*10^6' ], rotation=0, ha='center', va='top')
上面的效果不是我想看到的。我得到了:
但我想要以下内容:
我怎样才能做到这一点?
您需要使用数学符号。这与在 Latex 中一样,通过用 $
将数学表达式括起来。详细解释 here.
对于您的情况,您可以将字符串写为:
ax.set_yticklabels([ '.0 \cdot 10^6$', '.2 \cdot 10^6$',...], rotation=0, ha='center', va='top')
您可以在字符串中使用 unicode:
ax.set_yticklabels([ '1.0∙10⁶', '1.2∙10⁶', '1.4∙10⁶', '1.6∙10⁶', '1.8∙10⁶', '2.0∙10⁶', '2.2∙10⁶', '2.4∙10⁶' ], rotation=0, ha='center', va='top')