簡體   English   中英

將右側的 y 軸添加到 Seaborn 中的 Ridge Plot

[英]Adding y-axis on right side to Ridge Plot in Seaborn

我想在 Ridge 圖的右側添加一個示例 y 軸刻度,以了解所有圖的值范圍是多少。 最好我只想將它添加到一個子圖而不是所有子圖。

我的情節基於 seaborn 'ridge plot' 示例,網址為: https ://seaborn.pydata.org/examples/kde_ridgeplot.html

我嘗試了以下代碼但沒有運氣:

g.set(yticks=[0,200])
g.set_y_label_position("right")
g.set_ylabels('[Range]',fontsize=9,fontweight="normal")

如果您想從 FacetGrid 修改一個特定的軸,您可以從列表g.axes獲取參考

這是我將如何去做

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="white", rc={"axes.facecolor": (0, 0, 0, 0)})

# Create the data
rs = np.random.RandomState(1979)
x = rs.randn(500)
g = np.tile(list("ABCDEFGHIJ"), 50)
df = pd.DataFrame(dict(x=x, g=g))
m = df.g.map(ord)
df["x"] += m

# Initialize the FacetGrid object
pal = sns.cubehelix_palette(10, rot=-.25, light=.7)
g = sns.FacetGrid(df, row="g", hue="g", aspect=15, height=.5, palette=pal)

# Draw the densities in a few steps
g.map(sns.kdeplot, "x", clip_on=False, shade=True, alpha=1, lw=1.5, bw=.2)
g.map(sns.kdeplot, "x", clip_on=False, color="w", lw=2, bw=.2)
g.map(plt.axhline, y=0, lw=2, clip_on=False)


# Define and use a simple function to label the plot in axes coordinates
def label(x, color, label):
    ax = plt.gca()
    ax.text(0, .2, label, fontweight="bold", color=color,
            ha="left", va="center", transform=ax.transAxes)


g.map(label, "x")

#
# Changes from seaborn example below this point
#

# Set the subplots to overlap
g.fig.subplots_adjust(hspace=-.25, right=0.9)

# Remove axes details that don't play well with overlap
g.set_titles("")
#g.set(yticks=[])
g.despine(bottom=True, left=True, right=False, top=True, offset=5)

for ax in g.axes.ravel():
    if ax.is_first_row():  # can use .is_last_row() to show spine on the bottom plot instead
        ax.yaxis.tick_right()
        ax.yaxis.set_label_position("right")
        ax.set_ylabel("MW")
    else:
        ax.spines['right'].set_visible(False)
        [l.set_visible(False) for l in ax.get_yticklabels()]  # necessary because y-axes are shared

在此處輸入圖片說明

暫無
暫無

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

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