简体   繁体   English

如何从 Plotly Python 的 Box 中取出一些东西?

[英]How to remove something from the Box in Plotly Python?

Which line of this code:这段代码的哪一行:

# Take credit amount values into a list
young = df['Credit_amount'].loc[df['Age_Group'] == 'Young'].values.tolist()
young_adults = df['Credit_amount'].loc[df['Age_Group'] == 'Young Adults'].values.tolist()
senior = df['Credit_amount'].loc[df['Age_Group'] == 'Senior'].values.tolist()
elder_credit = df['Credit_amount'].loc[df['Age_Group'] == 'Elder'].values.tolist()

# Create the box plots by age category
young_credit = go.Box(
    y = young,
    name = "Young",
    jitter = 0.3,
    pointpos = -1.8,
    boxpoints = 'all',
    marker = dict(
        color = 'rgb(150, 198, 109)'),
    line = dict(
        color = 'rgb(111, 200, 37)')
)

young_adults_credit = go.Box(
    y = young_adults,
    name = "Young Adults",
    jitter = 0.3,
    pointpos = -1.8,
    boxpoints = 'all',
    marker = dict(
        color = 'rgb(124, 236, 212)'),
    line = dict(
        color = 'rgb(38, 214, 177)')
)

senior_credit = go.Box(
    y = senior,
    name = "Seniors",
    jitter = 0.3,
    pointpos = -1.8,
    boxpoints = 'all',
    marker = dict(
        color = 'rgb(241, 93, 93)'),
    line = dict(
        color = 'rgb(225, 44, 44)')
)

elder_credit = go.Box(
    y = elder_credit,
    name = "Elders",
    jitter = 0.3,
    pointpos = -1.8,
    boxpoints = 'all',
    marker = dict(
        color = 'rgb(180, 121, 72)'),
    line = dict(
        color = 'rgb(115, 77, 46)')
)

data = [young_credit, young_adults_credit, senior_credit, elder_credit]

layout = dict(
    title="Credit Amount by Age Group Segment", 
    xaxis = dict(title="Age Group"),
    yaxis= dict(title="Credit Amount")
)

fig = dict(data=data, layout=layout)
iplot(fig, filename="Box Plot")

concerns the fragments marked in the picture below, I would like to remove those fragments from the chart and which lines of code I have to remove to achieve this goal.关于下图中标记的片段,我想从图表中删除这些片段以及我必须删除哪些代码行才能实现这个目标。 I will be really thankfull for all clear answers because I can not find line of code to remove this fragments of plot. Thank you so much!我将非常感谢所有明确的答案,因为我找不到删除 plot 的这个片段的代码行。非常感谢!

在此处输入图像描述

If you Want to totally remove the points, you should remove parameters in each go.Box:如果你想完全删除点,你应该删除每个 go.Box 中的参数:

jitter = 0.3,
pointpos = -1.8,
boxpoints = 'all'

From plot.ly/python/box-plots/ : With the points argument, display underlying data points with either all points ( all ), outliers only ( outliers , default), or none of them ( False ).来自plot.ly/python/box-plots/ :使用points参数,显示所有点 ( all )、仅离群值 ( outliers , default ) 或都不显示 ( False ) 的基础数据点。

Plot 1: boxpoints = False Plot 1: boxpoints = False

在此处输入图像描述

Plot 2: boxpoints = 'all' Plot 2: boxpoints = 'all'

在此处输入图像描述

I got the same issue and can still not find the fix.我遇到了同样的问题,但仍然找不到解决方法。 The github issue is still open which Ahmed mentioned ( https://github.com/plotly/plotly.js/issues/277 ). Ahmed 提到的 github 问题仍然悬而未决 ( https://github.com/plotly/plotly.js/issues/277 )。

Although, you can use a visible work around.虽然,您可以使用可见的解决方法。 It does not fix the problem.它不能解决问题。 But for the vision it is fixed.但对于愿景来说,它是固定的。 You van marker=dict(opacity=0) which makes the points invisible.你 van marker=dict(opacity=0)这使得点不可见。 When you hover over them, they are still there.当你 hover 超过他们时,他们还在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM