Sumit Kumar
Sumit Kumar

Reputation: 17

BoxPlot for single point

When there is only one point in the data, box plot is coming empty. But what I am expecting is a degenrated plot which shows horizontal line corresponding to that point. Is it possible to do so? attaching sample data code which I tried

data1 = {'A':["Favorite"],
        'B':[0.413]}

data= pd.DataFrame(data1)

fig = go.Figure()

fig.add_trace(
            go.Box(
                x=data["A"],
                y=data["B"],
                name="",
                quartilemethod='exclusive',
                boxpoints=False,
                marker_color='#00528c',
            )
        )

I am getting something below enter image description here

But what I am expecting is something like a line corresponding to single point enter image description here

Thanks for your response!!

Upvotes: 0

Views: 353

Answers (1)

Rob Raymond
Rob Raymond

Reputation: 31146

extend your sample code to work with various sized arrays. Simple answer has to be >= 2 items to generate a box plot. https://plotly.com/python/box-plots/#box-plot-with-plotlyexpress A box plot is a statistical representation of the distribution of a variable through its quartiles. A list length 1 is not a distribution.

S = 2
data1 = {'A':np.repeat(["Favorite"], S),
        'B':np.repeat([0.413], S) * np.random.uniform(.98,1.02, S)}

data= pd.DataFrame(data1)

fig = go.Figure()

fig.add_trace(
            go.Box(
                x=data["A"],
                y=data["B"],
                name="",
                quartilemethod='exclusive',
                boxpoints=False,
                marker_color='#00528c',
            )
        )

Upvotes: 1

Related Questions