Comparisons are fundamental to data visualization as they enable viewers to understand relationships, differences, and trends within the data, ultimately uncovering the key takeaways of a chart. Whether comparing categories, time periods, or variables, visualizations such as bar charts, line graphs, or scatter plots highlight how values differ or correlate, providing context and meaning. For instance, a bar chart comparing sales across regions reveals top-performing areas, while a line chart showing revenue over time identifies growth or decline. Without clear comparisons, the data may appear isolated and lack actionable insights. By presenting data in a way that facilitates side-by-side evaluations, comparisons make it easier to identify patterns, spot outliers, and prioritize areas of focus, ensuring that the visualization effectively communicates its intended message.
Use the add_trace to add lines from a comparison stock on the line chart.
// Some code
import plotly.express as px
import pandas as pd
import yfinance as yf
#download boeing data for one year; interval = '1mo' for monthly data
boeing = yf.download('BA', period='1y', interval='1d')
boeing.reset_index(inplace=True)
boeing.columns = boeing.columns.to_flat_index()
boeing.columns = ['_'.join(col) for col in boeing.columns]
boeing.columns = ["Date", "Close", "High", "Low", "Open", "Volume"] # rename columns
# download Airbus data
airbus = yf.download('EADSY', period='1y', interval='1d')
airbus.reset_index(inplace=True)
airbus.columns = airbus.columns.to_flat_index()
airbus.columns = ['_'.join(col) for col in airbus.columns]
airbus.columns = ["Date", "Close_Airbus", "High_Airbus",
"Low_Airbus", "Open_Airbus", "Volume_Airbus"] # rename columns