• <bdo id='gtbTD'></bdo><ul id='gtbTD'></ul>

    <small id='gtbTD'></small><noframes id='gtbTD'>

    <legend id='gtbTD'><style id='gtbTD'><dir id='gtbTD'><q id='gtbTD'></q></dir></style></legend>
    <tfoot id='gtbTD'></tfoot>
      <i id='gtbTD'><tr id='gtbTD'><dt id='gtbTD'><q id='gtbTD'><span id='gtbTD'><b id='gtbTD'><form id='gtbTD'><ins id='gtbTD'></ins><ul id='gtbTD'></ul><sub id='gtbTD'></sub></form><legend id='gtbTD'></legend><bdo id='gtbTD'><pre id='gtbTD'><center id='gtbTD'></center></pre></bdo></b><th id='gtbTD'></th></span></q></dt></tr></i><div id='gtbTD'><tfoot id='gtbTD'></tfoot><dl id='gtbTD'><fieldset id='gtbTD'></fieldset></dl></div>

      海运热图子图-保持轴比一致

      Seaborn Heatmap Subplots - keep axis ratio consistent(海运热图子图-保持轴比一致)
        <bdo id='xbY8H'></bdo><ul id='xbY8H'></ul>

          1. <small id='xbY8H'></small><noframes id='xbY8H'>

                <tfoot id='xbY8H'></tfoot>
              • <legend id='xbY8H'><style id='xbY8H'><dir id='xbY8H'><q id='xbY8H'></q></dir></style></legend>
              • <i id='xbY8H'><tr id='xbY8H'><dt id='xbY8H'><q id='xbY8H'><span id='xbY8H'><b id='xbY8H'><form id='xbY8H'><ins id='xbY8H'></ins><ul id='xbY8H'></ul><sub id='xbY8H'></sub></form><legend id='xbY8H'></legend><bdo id='xbY8H'><pre id='xbY8H'><center id='xbY8H'></center></pre></bdo></b><th id='xbY8H'></th></span></q></dt></tr></i><div id='xbY8H'><tfoot id='xbY8H'></tfoot><dl id='xbY8H'><fieldset id='xbY8H'></fieldset></dl></div>

                  <tbody id='xbY8H'></tbody>
              • 本文介绍了海运热图子图-保持轴比一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如果我有以下代码:

                import seaborn 
                import matplotlib.pyplot as plt
                flights = sns.load_dataset("flights")
                flights = flights.pivot("month", "year", "passengers")
                f,(ax1,ax2,ax3) = plt.subplots(1,3,sharey=True)
                g1 = sns.heatmap(flights,cmap="YlGnBu",cbar=False,ax=ax1)
                g1.set_ylabel('')
                g1.set_xlabel('')
                g2 = sns.heatmap(flights,cmap="YlGnBu",cbar=False,ax=ax2)
                g2.set_ylabel('')
                g2.set_xlabel('')
                g3 = sns.heatmap(flights,cmap="YlGnBu",ax=ax3)
                g3.set_ylabel('')
                g3.set_xlabel('')
                

                它输出以下内容-

                如何调整子图以使g3轴与g1、g2轴的宽度相同。由于我没有在前两个轴上添加颜色条,所以Seborn将第三个轴向下缩小以使整个图形保持一致。这是可以理解的。

                我想要这个:

                也许我需要在第四个面板中只包含颜色条的情况下绘制4个面板的子图?

                推荐答案

                确实有一种方法是创建4个轴,其中第四个轴将包含颜色条。您可以使用cbar_ax参数告诉热图绘制颜色条的轴。为了创建具有良好比例的轴,可以使用gridspec_kw参数subplots。问题是,这些轴将与色条共享y比例,因此我们需要关闭共享,并使用ax1.get_shared_y_axes().join(ax2,ax3)手动共享前三个轴。这又会创建不需要的轴标签,需要将其关闭。

                import seaborn  as sns
                import matplotlib.pyplot as plt
                flights = sns.load_dataset("flights")
                flights = flights.pivot("month", "year", "passengers")
                f,(ax1,ax2,ax3, axcb) = plt.subplots(1,4, 
                            gridspec_kw={'width_ratios':[1,1,1,0.08]})
                ax1.get_shared_y_axes().join(ax2,ax3)
                g1 = sns.heatmap(flights,cmap="YlGnBu",cbar=False,ax=ax1)
                g1.set_ylabel('')
                g1.set_xlabel('')
                g2 = sns.heatmap(flights,cmap="YlGnBu",cbar=False,ax=ax2)
                g2.set_ylabel('')
                g2.set_xlabel('')
                g2.set_yticks([])
                g3 = sns.heatmap(flights,cmap="YlGnBu",ax=ax3, cbar_ax=axcb)
                g3.set_ylabel('')
                g3.set_xlabel('')
                g3.set_yticks([])
                
                # may be needed to rotate the ticklabels correctly:
                for ax in [g1,g2,g3]:
                    tl = ax.get_xticklabels()
                    ax.set_xticklabels(tl, rotation=90)
                    tly = ax.get_yticklabels()
                    ax.set_yticklabels(tly, rotation=0)
                
                plt.show()
                

                这篇关于海运热图子图-保持轴比一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                1. <i id='XSBEv'><tr id='XSBEv'><dt id='XSBEv'><q id='XSBEv'><span id='XSBEv'><b id='XSBEv'><form id='XSBEv'><ins id='XSBEv'></ins><ul id='XSBEv'></ul><sub id='XSBEv'></sub></form><legend id='XSBEv'></legend><bdo id='XSBEv'><pre id='XSBEv'><center id='XSBEv'></center></pre></bdo></b><th id='XSBEv'></th></span></q></dt></tr></i><div id='XSBEv'><tfoot id='XSBEv'></tfoot><dl id='XSBEv'><fieldset id='XSBEv'></fieldset></dl></div>
                  <tfoot id='XSBEv'></tfoot>

                2. <legend id='XSBEv'><style id='XSBEv'><dir id='XSBEv'><q id='XSBEv'></q></dir></style></legend>
                        <bdo id='XSBEv'></bdo><ul id='XSBEv'></ul>

                          <small id='XSBEv'></small><noframes id='XSBEv'>

                            <tbody id='XSBEv'></tbody>