首页 > 解决方案 > 你能提取 Matplotlib 对数轴中使用的对数的底吗?

问题描述

如果有人创建了 Matplotlib 图形,例如,

from matplotlib import pyplot as plt
import numpy as np
plt.plot([1, 2, 3, 4], [1, 2, 3, 4])
ax = plt.gca()
ax.set_xscale('log', basex=np.e)

有没有办法从轴中提取该basex值是什么?我可以得到xscalewith ax.get_xscale(),但没有等价物ax.get_basex()

标签: matplotliblogarithm

解决方案


由于get_scale返回name实际使用的matplotlib.scale.LogScale对象的字段ax.get_xaxis()._scale而不是对象本身,不幸的是我没有找到另一种方法,然后直接访问base私有字段_scale。不鼓励访问私有字段,但是

ax.get_xaxis()._scale.base

给你结果。


推荐阅读