6.1.1 Plotly Express
Plotly describes Plotly-express as a “terse, consistent, high-level API for rapid data exploration and figure generation”.
Plotly Express (px) is a built-in part of theplotly
library and is the recommended starting point for creating the most common figures. Every Plotly Express function uses graph objects internally and returns a figure instance.
Plotly Express provides more than 30 functions for creating different types of figures, from a scatter plot to a bar chart to a histogram to a sunburst chart throughout a data exploration session.
Plotly Express currently includes the following functions:
Basics:
scatter
,line
,area
,bar
,funnel
,timeline
Part-of-Whole:
pie
,sunburst
,treemap
,funnel_area
1D Distributions:
histogram
,box
,violin
,strip
2D Distributions:
density_heatmap
,density_contour
Matrix Input:
imshow
3-Dimensional:
scatter_3d
,line_3d
Multidimensional:
scatter_matrix
,parallel_coordinates
,parallel_categories
Tile Maps:
scatter_mapbox
,line_mapbox
,choropleth_mapbox
,density_mapbox
Outline Maps:
scatter_geo
,line_geo
,choropleth
Polar Charts:
scatter_polar
,line_polar
,bar_polar
Ternary Charts:
scatter_ternary
,line_ternary
Let's still use the tips dataset and gapmind dataset for example.
1. Scatter and Line
Here we can a strong positive correlation between tip and total_bill. The higher the total bill, the higher the tip. But could we know more from one figure?
We can add more parameters to make the scatter chart informative. On the top lays the boxplot distribution, on the right lays the violin plot distribution. Meanwhile, we distinguished each day's performance.
We also can consider using a parallel chart to illustrate the relationship. It compares the feature of several individual observations on a set of numeric variables. Each vertical bar represents a variable and often has its own scale. Values are then plotted as a series of lines connected across each axis.
2. Bar Chart
The scatter chart and line chart are not always the best way to display comparison. In this case, a bar chart is more appropriate. As we mentioned in chapter 3, the bar chart family includes grouped bar, stacked bar, and facet bar chart.
Grouped Bar
Stacked Bar
Facet Barplot
Compared to the above, the facet barplot has the best performance to illustrate the relationship between multiple variables.
3. Pie Chart
plotly.express
has a shorter way to create a fancy pie chart than matplotlib
and seaborn
.
4. Distribution
As we discussed in chapter 3 and chapter 4, the distribution family contains a histogram plot, boxplot, and violin plot.
In the plotly.express
(px), we can set the quick style by the parameter "template". Available templates:
The histogram plot uses the default template
The violin plot uses the 'plotly_dark' template
The boxplot uses the 'presentation' template, the font is bigger than others.
Histogram plot
Violin plot
Box plot
Last updated