Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PX auto-detect orientation for box/violin/histogram #2331

Closed
nicolaskruchten opened this issue Mar 30, 2020 · 8 comments · Fixed by #2336
Closed

PX auto-detect orientation for box/violin/histogram #2331

nicolaskruchten opened this issue Mar 30, 2020 · 8 comments · Fixed by #2336
Milestone

Comments

@nicolaskruchten
Copy link
Contributor

This shouldn't error out:

import plotly.express as px
import numpy as np
px.histogram(y=np.random.rand(100))

And this shouldn't render a blank plot:

import plotly.express as px
import numpy as np
px.box(x=np.random.rand(100))

Because in both cases PX should be smart enough to set orientation. In fact, even if both x and y are set, if one is categorical and the other isn't, we should be able to auto-detect the correct orientation (this would work well for bar also).

@emmanuelle
Copy link
Contributor

Totally agree, all the more than go does this correctly. Ideally we would find a way to let go do the job? I'm very much in favor of having a consistent behaviour between px and go wherever possible, since I've seen that when it's not the case it can be confusing for users (variable names etc.).

@nicolaskruchten
Copy link
Contributor Author

I agree it would be great to have Plotly.js do this also but I think it's likely we can do it in PX in an afternoon of work, whereas we have fewer resources in JS-land...

@emmanuelle
Copy link
Contributor

ok what I wrote was not clear enough. I meant that

go.Figure(go.Histogram(y=np.random.rand(1000)))

(horizontal histogram) and

go.Figure(go.Box(x=np.random.rand(1000)))

(horizontal box) work well in the sense that the orientation is automatically detected.

@nicolaskruchten
Copy link
Contributor Author

Huh, interesting! Thanks for pointing this out! I guess PX interferes with this somehow. Would be good to have it stop interfering :)

@nicolaskruchten
Copy link
Contributor Author

Ah, part of the reason for the box/violin case is that the JS layer puts the trace name on the opposing axis, which seemed wrong to me.

@emmanuelle
Copy link
Contributor

print(go.Figure(go.Box(x=np.random.rand(100))))

Figure({
    'data': [{'type': 'box',
              'x': array([0.32065228, 0.48994228, 0.70502421, 0.65397378, 0.95714642, 0.56621047,
                          0.43261323, 0.60429768, 0.08010901, 0.0022502 , 0.07976279, 0.53399751,
                          0.25428766, 0.37827088, 0.48184182, 0.88055022, 0.97269599, 0.11505104,
                          0.34777246, 0.08883559, 0.85529721, 0.37266017, 0.40183613, 0.86385668,
                          0.53972054, 0.22857269, 0.28570118, 0.42163051, 0.81264544, 0.99776746,
                          0.62439376, 0.21016085, 0.25382938, 0.81012574, 0.56425652, 0.26468222,
                          0.38649636, 0.43450504, 0.51158692, 0.37966258, 0.05371415, 0.59846598,
                          0.25882822, 0.47821963, 0.79881602, 0.08615973, 0.15192106, 0.54687209,
                          0.47867526, 0.52699594, 0.36006859, 0.4058679 , 0.74298336, 0.50287948,
                          0.54990132, 0.8883117 , 0.40090635, 0.76686281, 0.08047904, 0.22585636,
                          0.35675427, 0.66099582, 0.40048364, 0.49159497, 0.14414088, 0.24489358,
                          0.20494872, 0.34980492, 0.65345351, 0.48982552, 0.51010455, 0.24304684,
                          0.59714743, 0.1310927 , 0.30564158, 0.90141956, 0.80428732, 0.10125796,
                          0.30462085, 0.75144891, 0.38407896, 0.23433593, 0.3127956 , 0.86009993,
                          0.44678564, 0.72461996, 0.83974628, 0.32693944, 0.09265118, 0.35788925,
                          0.62547315, 0.69280587, 0.71919151, 0.46810547, 0.53171278, 0.80685974,
                          0.62733202, 0.76876099, 0.33144038, 0.03435217])}],
    'layout': {'template': '...'}
})

and

print(px.box(x=np.random.rand(100)))

Figure({
    'data': [{'alignmentgroup': 'True',
              'hoverlabel': {'namelength': 0},
              'hovertemplate': 'x=%{x}',
              'legendgroup': '',
              'marker': {'color': '#636efa'},
              'name': '',
              'notched': False,
              'offsetgroup': '',
              'orientation': 'v',
              'showlegend': False,
              'type': 'box',
              'x': array([0.53010571, 0.18609955, 0.86999703, 0.21952473, 0.02662023, 0.5172751 ,
                          0.55462782, 0.67961315, 0.30776178, 0.25063232, 0.50070613, 0.67302146,
                          0.96597865, 0.09599429, 0.40047438, 0.50152882, 0.05200231, 0.05327546,
                          0.50355829, 0.17279427, 0.41521471, 0.53108298, 0.97898325, 0.99223932,
                          0.3564994 , 0.8437124 , 0.8985033 , 0.90567597, 0.66303581, 0.00996149,
                          0.96331997, 0.28176957, 0.41422744, 0.00752991, 0.25408023, 0.25797074,
                          0.37880164, 0.56451364, 0.93649064, 0.22208826, 0.23228119, 0.52097624,
                          0.50397968, 0.90892426, 0.85567902, 0.40972804, 0.46234578, 0.50395533,
                          0.59695447, 0.72507557, 0.12363573, 0.21778269, 0.34938733, 0.57567852,
                          0.66378375, 0.31943721, 0.51835171, 0.95419906, 0.40287856, 0.87024703,
                          0.37309821, 0.74944507, 0.35284879, 0.12966159, 0.49456409, 0.34892478,
                          0.35245897, 0.90675228, 0.65068272, 0.78515876, 0.62233852, 0.56403913,
                          0.55382158, 0.64153443, 0.95656636, 0.33042593, 0.58613387, 0.74291058,
                          0.62264485, 0.73765197, 0.26166393, 0.42698692, 0.84952022, 0.20440105,
                          0.6144932 , 0.11635136, 0.08354765, 0.69024249, 0.18440466, 0.74332091,
                          0.89621696, 0.40049393, 0.9863931 , 0.18010234, 0.69612404, 0.0236499 ,
                          0.27061497, 0.25809072, 0.77960436, 0.95988681]),
              'x0': ' ',
              'xaxis': 'x',
              'y0': ' ',
              'yaxis': 'y'}],
    'layout': {'boxmode': 'group',
               'legend': {'tracegroupgap': 0},
               'margin': {'t': 60},
               'template': '...',
               'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'x'}},
               'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0]}}
})

@emmanuelle
Copy link
Contributor

emmanuelle commented Mar 30, 2020

the orientation is forced for px.box

fig = px.box(x=np.random.rand(100))
fig['data'][0].pop('orientation')
fig.show()

works as go

@emmanuelle
Copy link
Contributor

probably we could set the orientation only if the user specified it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants