简体   繁体   中英

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!

在此处输入图像描述

If you Want to totally remove the points, you should remove parameters in each 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 1: boxpoints = False

在此处输入图像描述

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 ).

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. When you hover over them, they are still there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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