deephaven / deephaven-plugins

Deephaven Plugins
11 stars 15 forks source link

fix: Make `dx` histogram behavior consistent with `px` #1002

Open jnumainville opened 2 weeks ago

jnumainville commented 2 weeks ago

Fixes: #668

The following examples are now basically consistent. During testing I discovered https://github.com/deephaven/deephaven-plugins/issues/1001 so the legend titles are not set in a couple of these, but that is beyond the scope of this ticket as that is a general plot by issue, not a histogram specific one.

Note a few intentional differences in the args. It's not expected that dx histograms and px histograms aggregate in the same exact way. Plotly infers the equivalent of range_bins hence the extra argument. Additionally we have barmode="group" as our default whereas in Plotly it is barmode="relative". I believe this was an intentional choice on our end because it's hard to compare the different traces with barmode="relative" although I don't have a record of it.

import plotly.express as px
import deephaven.plot.express as dx

df = px.data.tips()
fig = px.histogram(df, x="size", y="total_bill")
fig2 = px.histogram(df, x="size", y="total_bill", histfunc="count", nbins=6)
fig3 = px.histogram(df, x="size", y="total_bill", orientation="h", nbins=6)
fig4 = px.histogram(df, x="size", y="total_bill", orientation="h", histfunc="count", nbins=6)
fig5 = px.histogram(df, x=["tip", "total_bill"], y="size", nbins=6)
fig6 = px.histogram(df, x=["tip", "total_bill"], y="size", orientation="h", nbins=6)
fig7 = px.histogram(df, x="size", y=["tip", "total_bill"], nbins=6)
fig8 = px.histogram(df, x="size", y=["tip", "total_bill"], orientation="h", nbins=6)
fig9 = px.histogram(df, x=["tip", "total_bill"], y="size", histfunc="count", nbins=6)
fig10 = px.histogram(df, x=["tip", "total_bill"], y="size", orientation="h", histfunc="count")
fig11 = px.histogram(df, x="size", y=["tip", "total_bill"], histfunc="count", nbins=6)
fig12 = px.histogram(df, x="size", y=["tip", "total_bill"], orientation="h", histfunc="count", nbins=6)
fig13 = px.histogram(df, x="size", y=["tip", "total_bill"], histnorm="probability", barnorm="percent")
fig14 = px.histogram(df, x="size")
fig15 = px.histogram(df, y="size")

fig1d = dx.histogram(df, x="size", y="total_bill", nbins=6, range_bins=[0, 7])
fig2d = dx.histogram(df, x="size", y="total_bill", histfunc="count", nbins=6, range_bins=[0, 7])
fig3d = dx.histogram(df, x="size", y="total_bill", orientation="h", nbins=6, range_bins=[0, 60])
fig4d = dx.histogram(df, x="size", y="total_bill", orientation="h", histfunc="count", nbins=6, range_bins=[0, 60])
fig5d = dx.histogram(df, x=["tip", "total_bill"], y="size", nbins=6, range_bins=[0, 60], barmode="relative")
fig6d = dx.histogram(df, x=["tip", "total_bill"], y="size", orientation="h", nbins=6, range_bins=[0, 7], barmode="relative")
fig7d = dx.histogram(df, x="size", y=["tip", "total_bill"], nbins=6, range_bins=[0, 7], barmode="relative")
fig8d = dx.histogram(df, x="size", y=["tip", "total_bill"], orientation="h", nbins=6, range_bins=[0, 60], barmode="relative")
fig9d = dx.histogram(df, x=["tip", "total_bill"], y="size", histfunc="count", nbins=6, range_bins=[0, 60], barmode="relative")
fig10d = dx.histogram(df, x=["tip", "total_bill"], y="size", orientation="h", histfunc="count", nbins=6, range_bins=[0, 7], barmode="relative")
fig11d = dx.histogram(df, x="size", y=["tip", "total_bill"], histfunc="count", nbins=6, range_bins=[0, 7], barmode="relative")
fig12d = dx.histogram(df, x="size", y=["tip", "total_bill"], orientation="h", histfunc="count", nbins=6, range_bins=[0, 60], barmode="relative")
fig13d = dx.histogram(df, x="size", y=["tip", "total_bill"], histnorm="probability", barnorm="percent", range_bins=[0,7], nbins=6, barmode="relative")
fig14d = dx.histogram(df, x="size", nbins=6)
fig15d = dx.histogram(df, y="size", nbins=6)