Matplotlib:在对数图中禁用10的幂 [英] Matplotlib: disable powers of ten in log plot

查看:89
本文介绍了Matplotlib:在对数图中禁用10的幂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法可以使matplotlib在对数图中不显示10的幂,而仅显示数字?即,不是显示[10, 100, 1000]而是显示[10, 100, 1000]?我不想更改刻度线的位置,只想摆脱十的幂.

Is there a simple way to make matplotlib not show the powers of ten in a log plot, and instead just show the numbers? I.e., instead of [10^1, 10^2, 10^3] display [10, 100, 1000]? I don't want to change the tickmark locations, just want to get rid of the powers of ten.

这是我目前拥有的:

This is what I currently have:

我可以通过xticks来更改标签本身,但是随后我得到了y刻度标签的字体或大小不匹配.我正在使用TeX编写此文本.我尝试了以下方法:

I can change the labels themselves via xticks, however I then get mismatching fonts or sizes for the y tick labels. I am using TeX for this text. I've tried the following:

xx, locs = xticks()
ll = [r'\rm{%s}' % str(a) for a in xx]
xticks(xx, ll)

这将产生以下结果:

This gives the following result:

在这种情况下,我可以使用相同的LaTeX罗马字体,但是大小和外观与y轴上的不同.另外,如果我在matplotlib中使用了不同的LaTeX字体,这将是有问题的.

In this particular case, I could use the same LaTeX roman font, but the sizes and looks are different to those in the y axis. Plus, if I used a different LaTeX font in matplotlib this is going to be problematic.

是否有更灵活的方式来关闭十种符号的功效?

Is there a more flexible way of switching off the power of ten notation?

推荐答案

使用 ScalarFormatter :

from matplotlib import rc
rc('text', usetex=True)
rc('font', size=20)

import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter

fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot(111)
ax.semilogx(range(100))
ax.xaxis.set_major_formatter(ScalarFormatter())
plt.show()

这篇关于Matplotlib:在对数图中禁用10的幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆