Skip to content

Match legend order to visual data order

badcolor and encodingmechanicalWilke 2019 p. 248

Which stock finished highest and which finished lowest over 2018?

Plotly Express Stocks dataset, first 53 weekly observations for four tech stocks.

“If there is a visual ordering in your data, make sure to match it in the legend”

Claus O. Wilke, "Fundamentals of Data Visualization", p. 248.
CVD preview

Before

Alphabetical legend order places Apple first and Facebook third even though Amazon finishes highest and Facebook finishes lowest.

Download before Python code

After

Ordering traces by their final level and placing direct labels beside the line ends aligns text order with the curves.

Download after Python code

Values

At year end Amazon stands near 1.24, Microsoft near 1.15, Apple near 0.85, and Facebook near 0.72.

Download all values as CSV