簡體   English   中英

在seaborn facetgrid的各個方面設置軸限制

[英]set axis limits on individual facets of seaborn facetgrid

我正在嘗試為 Seaborn facetgrid distplot 的每個方面將 x 軸限制設置為不同的值。 我知道我可以通過g.axes訪問子圖中的所有軸,所以我嘗試遍歷它們並設置 xlim :

g = sns.FacetGrid(mapping, col=options.facetCol, row=options.facetRow, col_order=sorted(cols), hue=options.group)
g = g.map(sns.distplot, options.axis)   

for i, ax in enumerate(g.axes.flat): # set every-other axis for testing purposes
        if i % 2 == 0[enter link description here][1]:
            ax.set_xlim(-400,500)
        else:
            ax.set_xlim(-200,200)

但是,當我這樣做時,所有軸都設置為 (-200, 200),而不僅僅是其他所有方面。

我究竟做錯了什么?

mwaskom有解決方案; 在此處發布完整性 - 只需將以下行更改為:

g = sns.FacetGrid(mapping, col=options.facetCol, row=options.facetRow, col_order=sorted(cols), hue=options.group, sharex=False)

正如mwaskom所建議的,您可以簡單地使用FacetGridsharex (分別為sharey )來允許圖具有獨立的軸比例:

share{x,y} : bool, 'col', 或 'row' 可選

如果為 true,則分面將跨列共享 y 軸和/或跨行共享 x 軸。

例如,與:

  • sharex=False每個圖都有自己的軸
  • sharex='col'每列都有自己的軸
  • sharex='row'每一行都有自己的軸(即使這個軸對我來說沒有太大意義)
sns.FacetGrid(data, ..., sharex='col')

如果您間接使用 FacetGrid,例如通過displotrelplot ,則必須使用facet_kws關鍵字參數:

sns.displot(data, ..., facet_kws={'sharex': 'col'})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM