python - 如何使用 2 y 缩放轴和共享 X 轴进行绘图?
问题描述
我正在尝试在同一图表上绘制一个带有一些 y 轴的浮动聚集条形图,其中一些散点图数据具有相同的 X 单位但不同的 y 单位。
我尝试使用函数 axis.twinx() 遵循以下帖子中的示例
https://matplotlib.org/gallery/api/two_scales.html
由于我的条形图的 x 最大值为 2400,而我的散点图的 x 最大值约为 1600,因此具有共享 x 轴的新组合图表将与显示的轴与散点图上的值不匹配。
例如。散点图最终值 (1600, y) 的位置以图形方式显示 x =2400,但当悬停在该点上时,这些点正确显示为 (1600, y)。
如何使用 x 中第二个轴的正确缩放来完成这 2 个缩放的 Y 轴?
plt,clf()
fig, ax1 = plt.subplot()
#part of my bar graph code
#pw_min = plt.barh(y_pos, w_min,gwidth)
ax1.pw_max52 = plt.barh(y_pos+4*gw, w_max52, height = gw, left = w_min, color = 'b')
ax1.pw_max89 = plt.barh(y_pos+2*gw, w_max89, height = gw, left = w_min, color = 'r')
#ax.twinx()
ax2 = ax1.twinx()
#plotting the scatter plot on the second axes we just made with twinx()
hwscat = ax2.plot(xsca, ysca, 'g.',xscb, yscb, 'b.')
plt.show()
似乎第二把斧头只是将绘图放置在空间中的位置,但并未将它们与其正确的 x 值相关联。
解决方案
推荐阅读
- arcore - 如何渲染始终沿运动移动的对象
- javascript - 为什么返回的结果中没有“String#match / RegExp#exec”的附加属性?
- java - 如何知道 JTable 何时已排序
- javascript - How to sent id from one page to another when click on submit?
- angular6 - 如何在Angular6中读取和显示非结构化Excel工作表数据
- sql - 我使用 LIKE 和通配符创建了一个 PDO 准备好的语句。目的是寻找一名工作人员
- java - 使用 apache-commons-fileupload 在 Spring 中上传文件时出现问题
- powershell - 如何丢弃 PowerShell ActiveDirectory cmdlet 的错误?
- apache-camel - 骆驼路线测试 - 注册表:模拟:结果
- c - Can alloca() memory be reallocated?