deephaven / deephaven-plugins

Deephaven Plugins
11 stars 15 forks source link

Strip plot does not actually render data points by default #548

Open alexpeters1208 opened 5 months ago

alexpeters1208 commented 5 months ago

Create a strip plot with dx.strip:

import plotly.express as px
from deephaven.pandas import to_table

tips = to_table(px.data.tips())

bill_distr = dx.strip(tips, x="total_bill", by="day")

The frame of the plot and axis labels will render, but the points themselves do not show up:

Screenshot 2024-06-13 at 10 10 58 AM

If you include a color explicitly:

bill_distr = dx.strip(tips, x="total_bill", by="day", color_discrete_sequence=["red"])

The plot will show up correctly:

Screenshot 2024-06-13 at 10 11 13 AM
chipkent commented 3 months ago

See https://github.com/deephaven/deephaven-plugins/pull/554#discussion_r1688655915

jnumainville commented 2 months ago

This appears to be a theming edge case

Essentially, a strip plot is a box plot with the box hidden and all points showing. The edge case arises because of how that box is hidden

import deephaven.plot.express as dx

stocks = dx.data.stocks()

fig_strip = dx.strip(
    stocks, 
    x="Price",
    by="Sym"
)

This is the same case as Alex originally posted, it's just empty Note that these traces have 'line': {'color': 'rgba(255,255,255,0)'} Setting that alpha to 0 is what makes the box transparent of course Now see this example

def testb(f):
    f.update_traces(line={'color': 'blue'}, boxpoints="all")

fig_strip_blue = dx.strip(
    stocks, 
    x="Price",
    by="Sym",
    unsafe_update_figure=testb
)

Image As you can see, the points themselves are inheriting the color from line

This can of course be overriden, I'll just do it through unsafe_update_figure

def testrb(f):
    f.update_traces(line={'color': 'blue'}, boxpoints="all", marker={'color':'red'})

fig_strip_red_blue = dx.strip(
    stocks, 
    x="Price",
    by="Sym",
    unsafe_update_figure=testrb
)

Image

But, the problem is, we strip the marker color (as we should) but since we use the colorway for the theme, the marker inherits the transparent line color I can remove the line color and this is themed "properly", but then the line is there when we don't want it.

def testl(f):
    f.update_traces(line=None, boxpoints="all")

fig_strip_themed = dx.strip(
    stocks, 
    x="Price",
    by="Sym",
    unsafe_update_figure=testl
)

Image

@bmingles @mattrunyon what do you think would be the best solution for this?

bmingles commented 2 months ago

@jnumainville Why does line=None still show the lines?

jnumainville commented 2 months ago

Because the way they are hidden is through setting the line color to be completely transparent in the trace 'line': {'color': 'rgba(255,255,255,0)'} Setting line=None doesn't get rid of the lines, just the color

bmingles commented 2 months ago

@jnumainville How about setting line width to 0.

f.update_traces(line={'color':None,'width': 0}, boxpoints="all")
jnumainville commented 2 months ago

That almost works, but the legend doesn't show up correctly. I'm guessing plotly doesn't handle a width of 0 in the legend. This happens in plotly and px too. Might be worth opening a ticket.

import plotly.express as px

df = px.data.tips()

fig = px.strip(df, x="total_bill", y="day", color="time")
new_fig = fig.update_traces(line={"color": None, "width": 0})
new_fig.show()
Screenshot 2024-09-16 at 12 14 22 PM
jnumainville commented 2 months ago

I opened https://github.com/plotly/plotly.js/issues/7159

mofojed commented 1 month ago

PR opened against plotly for this: https://github.com/plotly/plotly.js/pull/7162