Python中文
首页
教程
问答
标签
搜索
登录
注册
在python中同时绘制imshow和line plot
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>好吧,我完全被一个<a href="https://www.cnpython.com/qa/" class="inner-link">python问题</a>困住了。我认为过于详细地描述这个问题是令人困惑的,所以我将总结问题,然后展示我的代码。在</p> <p>我已经创建了一个imshow图,在上面,我想绘制一个常规的直线图。Y轴是不同的,这很好,但是X轴应该是相同的。在</p> <p>它几乎可以工作,除了缩放:</p> <pre><code>fig = plt.figure() ax1 = fig.add_subplot(111) ax1.set_xlabel('MJD',fontsize=14) ax1.set_ylabel('Bin Number',fontsize=14) mjdaxis=np.linspace(0,bad_removed_mjd.shape[0]-1,20).astype('int') ax1.set_xticks(mjdaxis,[int(np.floor(bad_removed_mjd[i])) for i in mjdaxis]) ax1.imshow(residuals, aspect="auto") ax2 = ax1.twinx() ax2.set_ylabel('Pdot (s-2)',fontsize=14) ax2.plot(pdot[8:,0],pdot[8:,1]) plt.show() </code></pre> <p>现在发生的是imshow图在x轴上的值0-60之间被压缩。这是因为它们现在被标绘为指数0,1,2。。。。我需要他们的x轴值对应于列表中的值'bad\mjd_removed'55304,55365,55401。。。。当我有一个单独的imshow情节的时候,这很好用。在</p> <p>以下是imshow图本身的图片,然后当我试图在其上添加线条图时:</p> <p><img src="https://i.imgur.com/koKIP.png" alt="plot with imshow only"/> <img src="https://i.imgur.com/7F8Vq.png" alt="plot with imshow and line plot"/></p> <p>在第二张图上,x轴上0左右的细线是压缩在0和60之间的图片1的全部。在</p> <p>在这个问题上我将非常感激任何帮助。谢谢您。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您可以使用imshow的extend=关键字,例如</p> <pre><code>plt.imshow(extend=(mjdaxis.min(),0,mjdaxis.max(),1000) </code></pre> <p>或者类似的事情。 但是你也应该记住,如果mjdaxis记号之间的间隙不是恒定的,你的直线图不会直接对应于图像,因为imshow图不会以与直线图相同的方式拉伸</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何添加虚拟方法
6 回答
如何添加表示整数的擦边字符串?
3 回答
如何添加要在Bokeh中使用的新font.ttf文件?
10 回答
如何添加要显示的矩阵XY轴编号和XY轴
10 回答
如何添加计数?
7 回答
如何添加计数器函数?
8 回答
如何添加计数器列来计算数据帧中另一列中的特定值?
5 回答
如何添加计数器来跟踪while循环中的月份和年份?
3 回答
如何添加计数并删除countplot的顶部和右侧脊椎?
1 回答
如何添加计时器wx.应用程序更新窗口对象的主循环?
9 回答
如何添加评论到帖子?PostDetailVew,Django 2.1.5
8 回答
如何添加评论拉梅尔亚姆
6 回答
如何添加诸如矩阵Python/Pandas之类的数据帧?
5 回答
如何添加谷歌地点自动完成到Flask?
1 回答
如何添加超时、python discord bot
8 回答
如何添加超过1dp的检查
7 回答
如何添加距离方法
4 回答
如何添加跟随游戏的敌人精灵
4 回答
如何添加路径以便python可以找到程序?
2 回答
如何添加身份验证/安全性以使用happybase访问HBase?
10 回答