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
plotly
now 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,x
andy
should behave similarly. (#2336)- New datasets have been added to
plotly.express.data
:stocks
,experiment
,medals_wide
andmedals_long
. (#2336) - plotly
go.Figure
andgo.FigureWidget
now 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
,boxmode
andstripmode
arguments for 2d-cartesian functions in Plotly Express (i.e.scatter
,line
,area
,bar
,histogram
,violin
,box
,strip
,funnel
,density_heatmap
anddensity_contour
) has been refined (#2336):- wide-form data support: if either
x
ory
(but not both) may now be provided as a list of column references intodata_frame
or 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
x
nory
is provided butdata_frame
is, the data frame will be treated as "wide" with defaults depending on the value oforientation
(andorientation
has accordingly been added toscatter
,line
,density_heatmap
, anddensity_contour
for this purpose). Previously this would have resulted in an empty figure. - if
x
ory
is missing, it is inferred to be the index ofdata_frame
ifdata_frame
provided, 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.histogram
and 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,orientation
now defaults tov
(h
). Previously it always defaulted tov
but this is not considered a breaking change, as the cases in which it now defaults toh
caused unreadable output if set tov
. - if both
x
andy
are provided and one of them does not contain continuous values,orientation
defaults to the value perpendicular to that axis. Previously it always defaulted tov
but this is not considered a breaking change, as the cases in which it now defaults toh
caused unreadable output if set tov
. - if both
x
andy
are provided tohistogram
, and ifx
,y
andz
are provided todensity_heatmap
ordensity_contour
, thenhistfunc
now defaults tosum
so as to avoid ignoring the provided data, and to causehistogram
andbar
to behave more similarly. violinmode
,boxmode
andstripmode
now default tooverlay
ifx
(y
) in inv
(h
) orientation is also mapped tocolor
, to avoid strange spacing issues with the previous default ofgroup
in all cases.
- wide-form data support: if either
- The Plotly Express arguments
color_discrete_map
,symbol_map
andline_dash_map
now accept the string"identity"
which causes the corresponding input data to be used as-is rather than mapped intocolor_discrete_sequence
,symbol_sequence
orline_dash_sequence
, respectively. (#2336) - Plotly Express now accepts
px.Constant
orpx.Range
objects in the place of column references so as to express constant or increasing integer values. (#2336)