v4.8.0 - Plotly Express Support for Wide- and Mixed-Form Data, plus a Pandas backend
See the full announcement at https://community.plotly.com/t/announcing-plotly-py-4-8-plotly-express-support-for-wide-and-mixed-form-data-plus-a-pandas-backend/40048
Key new documentation pages:
Added
plotlynow provides a Plotly Express-backed Pandas-compatible plotting backend, which can be activated viapandas.options.plotting.backend = "plotly". Note that it is not intended to implement every Pandas plotting function, nor is it intended to replicate the behaviour of every argument, although per the changes below,xandyshould behave similarly. (#2336)- New datasets have been added to
plotly.express.data:stocks,experiment,medals_wideandmedals_long. (#2336) - plotly
go.Figureandgo.FigureWidgetnow have a_repr_html_and a_repr_mimebundle_method, which are standard hooks for integration in systems based on IPython. In particular, with_repr_html_plotly figures can now be used within sphinx-gallery without any scraper. These additions should not change anything to the way plotly figures are displayed in notebook environments, since the_ipython_display_method (already present in earlier versions) takes precedence over the new methods.
Updated
- The behaviour of the
x,y,orientation,histfunc,violinmode,boxmodeandstripmodearguments for 2d-cartesian functions in Plotly Express (i.e.scatter,line,area,bar,histogram,violin,box,strip,funnel,density_heatmapanddensity_contour) has been refined (#2336):- wide-form data support: if either
xory(but not both) may now be provided as a list of column references intodata_frameor columns of data, in which case the imputed data frame will be treated as "wide" data andmelt()ed internally before applying the usual mapping rules, with function-specific defaults. - if neither
xnoryis provided butdata_frameis, the data frame will be treated as "wide" with defaults depending on the value oforientation(andorientationhas accordingly been added toscatter,line,density_heatmap, anddensity_contourfor this purpose). Previously this would have resulted in an empty figure. - if
xoryis missing, it is inferred to be the index ofdata_frameifdata_frameprovided, otherwise a stable index of integers starting at 0. In the case ofpx.bar, if the provided value is not continuous, the missing value is treated as a column of 1s named "count", so as to behave more likepx.histogramand to avoid sizing the resulting bars differently based on their position in the column. Previously, missing values defaulted to integers starting at 0 per trace which made it potentially inconsistent or misleading. - if
x(y) is missing,orientationnow defaults tov(h). Previously it always defaulted tovbut this is not considered a breaking change, as the cases in which it now defaults tohcaused unreadable output if set tov. - if both
xandyare provided and one of them does not contain continuous values,orientationdefaults to the value perpendicular to that axis. Previously it always defaulted tovbut this is not considered a breaking change, as the cases in which it now defaults tohcaused unreadable output if set tov. - if both
xandyare provided tohistogram, and ifx,yandzare provided todensity_heatmapordensity_contour, thenhistfuncnow defaults tosumso as to avoid ignoring the provided data, and to causehistogramandbarto behave more similarly. violinmode,boxmodeandstripmodenow default tooverlayifx(y) in inv(h) orientation is also mapped tocolor, to avoid strange spacing issues with the previous default ofgroupin all cases.
- wide-form data support: if either
- The Plotly Express arguments
color_discrete_map,symbol_mapandline_dash_mapnow accept the string"identity"which causes the corresponding input data to be used as-is rather than mapped intocolor_discrete_sequence,symbol_sequenceorline_dash_sequence, respectively. (#2336) - Plotly Express now accepts
px.Constantorpx.Rangeobjects in the place of column references so as to express constant or increasing integer values. (#2336)