python - Matplotlib secondary_xaxis 无法格式化
问题描述
我正在尝试以对数刻度将“反向”第二个 x 轴转换为 x 轴。secondary_xaxis工作正常,但我不能像往常一样格式化刻度。这是一个错误还是我错过了什么?
这就是我所做的:
import matplotlib.pyplot as plt
import numpy as np
fig, axs = plt.subplots(figsize=(0.6*4,0.6*3))
y = np.random.rand(10)
x = np.linspace(30,200,num=10)
p = plt.plot(x, y, marker='o', markersize=3)
plt.xscale("log")
def m2rho(m):
return 1 / m * 1000
def rho2m(rho):
return 1 / rho / 1000
secax = axs.secondary_xaxis('top', functions=(m2rho, rho2m))
from matplotlib.ticker import ScalarFormatter, NullFormatter
for axis in [axs.xaxis, secax.xaxis]:
axis.set_major_formatter(ScalarFormatter())
axis.set_minor_formatter(NullFormatter())
axs.set_xticks([50, 100, 200])
secax.set_xticks([20,10,5])
plt.tight_layout()
plt.show()
导致:
所以基本上顶部的第二个轴应该以非科学数字显示刻度 20、10 和 5,但事实并非如此。
解决方案
推荐阅读
- matlab - 将矩阵中的垂直向量的值分配给 MATLAB r2019b 中的变量
- twitter-bootstrap - bootstrap 3.4.1 和 4.0.0 中元素的对齐外观和感觉不同
- javascript - 从 WebDataRocks “时间” JSON 类型中删除 :ss 部分
- javascript - 我想修复单击菜单按钮的问题
- sql - oracle sql中的条件COUNT(1)= 1是什么意思
- c++ - 数组的静态与动态内存分配
- delphi - 从 Delphi 中提取 TWebBrowser 中的 iframe 内容
- python - 如何以正确的方式为独立的 python 应用程序制作 setup.py?
- jquery - 主页活动类无法删除
- python-3.x - ZMQ 错误:zmq.error.ZMQError:权限被拒绝