- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用以下代码用带状图覆盖箱线图:
# create a color palette
palette = ['tab:blue', 'tab:orange', 'tab:red',]
# plot the data
plt.figure(figsize = (18,8))
sns.stripplot(data = int_genes_melt, y = 'value', x = 'Genes', color = 'black')
sns.boxplot(data = int_genes_melt, y = 'value', x = 'Genes', hue = 'pulldown', hue_order= ['BT474', 'both', 'SKBR3'], palette = palette)
plt.ylabel('relative protein abundance to control')
plt.xticks(rotation=40)
sns.despine()
输出看起来像这样:
如您所见,条状图中的一些数据点与箱线图(箱线图橙色)完美重叠。然而,左边的第一个红色箱线图似乎并没有很好地与带状图重叠。为什么会发生这种情况有什么建议吗?
最佳答案
这是因为 int_genes_melt
中并非所有类型的 'Genes'
都具有这三种类型(['BT474', 'both', 'SKBR3' ]
) 的 'pulldown'
。
以'Genes'
的第一个类别(图中的第一个框和相关点)为例。只有一个红框,表示第一类中所有数据点的'pulldown'
属性为'SKBR3'
('SKBR3'
根据 hue_order
着色为 'tab:red'
。
箱线图行为。表示 'BT474'
和 'both'
的框丢失了。这是因为第一类中没有这样的数据具有这两种'pulldown'
。因此,只有属于 'Genes'
第一类的三个框的最后一个被绘制。
stripplot行为,第一类的点绘制在中心,关于'both'
的第二个方框所在的位置,就在方框的左边'SKBR3'
。
所以你可以看到在第一类中,点位于框的左侧。再举一个例子,在第五类中,然而,所有数据都有 'both'
作为它们的 'pulldown'
属性,所以绘制了三个框的第二个框,只是与带状图对齐。
可以引用the document of boxplot ,在页面搜索“Draw a boxplot with nested grouping when some bins are empty”,你可以找到一个说明箱线图这种行为的官方例子。
您可以添加hue='pulldown'
属性并设置dodge=True
。这样,每个类别的stripplot也会根据pulldown
属性分成三个 strip 。
可以引用the document of stripplot你会发现你可以“在主要分类轴上的不同位置绘制色调变量的每个级别”。
以下是代码示例:
没有这个 hue=
和 dodge=True
:
import seaborn as sns
import matplotlib.pyplot as plt
palette = ['tab:blue', 'tab:orange']
tips = sns.load_dataset("tips")
sns.stripplot(data=tips, y='total_bill', x='day', color='black')
sns.boxplot(data=tips, x="day", y="total_bill", hue="time", hue_order=['Lunch', 'Dinner'], palette=palette)
sns.despine()
plt.show()
其中给出(注意箱线图和条状图没有对齐,第三和第四列就像你的情况):
import seaborn as sns
import matplotlib.pyplot as plt
palette = ['tab:blue', 'tab:orange']
tips = sns.load_dataset("tips")
sns.stripplot(data=tips, y='total_bill', x='day', hue="time", dodge=True, color='black')
sns.boxplot(data=tips, x="day", y="total_bill", hue="time", hue_order=['Lunch', 'Dinner'], palette=palette)
sns.despine()
plt.show()
至于您的代码,我认为您应该使用(正如@Michael 指出的那样):
sns.stripplot(data=int_genes_melt, y='value', x='Genes', hue='pulldown', hue_order=['BT474', 'both', 'SKBR3'], dodge=True, color='black')
您也可以关闭引用 this link 的图例如果你愿意的话。
关于python - 将箱线图与 stripplot 叠加的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72887125/
我使用以下代码用带状图覆盖箱线图: # create a color palette palette = ['tab:blue', 'tab:orange', 'tab:red',] # plot t
我正在尝试创建一个像 this one 这样的图形来自 seaborn 文档,但 strip 图的边缘颜色由色调决定。这是我的尝试: import seaborn as sns df = sns.lo
我一直在努力为我的分类变量 (x=Type) 获取所需的错误栏,其中有两个不同的标记形状(每个类别 A 和 B),并且错误栏颜色与相应标记颜色的颜色相匹配(即palette=dict(A= "k",
我正在尝试使用 stripplot 绘制数据集。这是头部(有 25 列): Labels Acidobacteria Actinobacteria Armatimonadetes Ba
我有两个 DataFrame,我正在将它们绘制为 strip 图。我几乎可以随心所欲地绘制它们,但我想知道是否可以为“色调”添加类别标签。 目前的剧情是这样的: 但是,我想为每个字母的每个“列”添加类
我在 seaborn 上使用 stripplot 来显示一系列金属中心的 d 轨道的能量。 这是数据框: dxy dyz dz2 dxz dx2-y2
我正在使用 Python 3 和 Seaborn 制作分类 strip 图(请参见下面的代码和图片)。 每个 stripplot 有 2 个数据点(每个性别一个)。 import numpy as n
我在使用 Seaborn 在 Python 中创建的绘图中添加误差条时遇到了一些困难。 我目前有一个“csv”格式的数据框; TSMdatabase = 'TSMvsRunmaster.csv'; t
我有一个像这样的 Pandas 数据框: NAME POSITION VALUE A 123 0.1 B 34 0.8 如果用带状图创建一个图,有没有办法让点实际上是 NAME 中的相应值? 例如,教
我正在尝试创建一个 stripplot,其中 x 轴上的参数名称是希腊字母。那么我希望我的情节用希腊字母而不是“theta”、“rho”和“tau”下标来标记是很合乎逻辑的。我的策略是隐藏原始标签并在
我有可以很好地绘制 sns stripplot 的代码: f, ax = plt.subplots(figsize=(15,12)) sns.stripplot(data = cars, x='pri
我在 seaborn 中有以下情节: df = pandas.DataFrame({"sample": ["X", "X", "X", "Y", "Y", "Y"],
是否可以在 seaborn 的带状图上标注每个点?我的数据在 Pandas 数据框中。我知道注释适用于 matplotlib,但我发现它在这种情况下不起作用。 最佳答案 您只需要返回 axes 对象。
我有以下代码来绘制箱线图并将所有数据点叠加在条形图上。 import pandas as pd import seaborn as sns import matplotlib.pyplot as pl
我有以下代码来绘制箱线图并将所有数据点叠加在条形图上。 import pandas as pd import seaborn as sns import matplotlib.pyplot as pl
我正在尝试使用 seaborn.stripplot() 来做分类图,如下所示,使用可重现的代码: import seaborn as sns df = sns.load_dataset('iris')
我是一名优秀的程序员,十分优秀!