python - matplotlib 中 twinx() 期间的 RuntimeError
问题描述
执行 plt.twinx() 时出现以下错误
RuntimeError: Locator attempting to generate 1993 ticks from 0.075257498916 to 199.95917462: exceeds Locator.MAXTICKS
对应的代码是:
x1 = np.ones(100)*np.median(a)
y1 = np.linspace(1,500,100)
position_x = (np.around(np.linspace(0.0, np.max(a),6),2)).astype(int)
def tick_function(x):
"""Specify tick format"""
return ["%2.f" % i for i in x]
def func(x):
"""This can be anything you like"""
funcx=np.log10(1.0+x)
return funcx
fig=plt.figure(figsize=(7,6),dpi=100)
plt.hist(log_z, bins=40, histtype='step')
y_hist = plt.twiny()
y_hist.set_yticks(func(position_x))
y_hist.set_yticklabels(tick_function(position_x))
y_hist.set_ylabel('z')
plt.show()
我无法弄清楚为什么会这样。对此错误的来源和修复它的任何建议表示赞赏。PS 我使用的是 Python 2.7 和 matplotlib 版本 2.2.4。
解决方案
推荐阅读
- c# - 使用主键节点将 TSQL 转换为 NoSQL
- json - 如何在 Macos Catalina 上使用 Atom 1.58.0 x64 在我的 JSON 文件中查找和删除带有换行符和空格的模式?
- c# - Selenium Microsoft 登录“您的浏览器有点不寻常……”消息
- java - Spring 表达式语言 - 从 JSON 中获取值并创建字符串数组
- python - 在 python 乌龟绘图中隐藏乌龟
- selenium - Chrome 没有通过詹金斯在量角器测试中启动
- javascript - 在 POST 方法中使用 res.download() 下载文件会引发 405 (Nginx)
- html - @media(max-width:1200px) 直到 1183px 才响应
- r - DT::datable 使用 Shiny App 手动调整列宽
- ios - 将任意视频文件重新编码为单个标准化 FPS、分辨率、旋转等