Five Non‑Traditional Plotly Visualizations to Level Up Your Data Storytelling
This article introduces five advanced Plotly visualization techniques—including animated bar charts, scatter animations, sunburst diagrams, parallel categories, parallel coordinates, and gauge indicators—showcasing how to create dynamic, interactive graphics in Python to make data stories more compelling and insightful.
Data scientists need compelling visual stories, and Plotly provides a powerful, integrated library for creating dynamic and interactive charts that can be embedded in notebooks, websites, or Dash applications.
Plotly’s strong integration with Jupyter Notebook, web embedding, and the Dash framework makes it ideal for building dashboards and analytical apps.
To get started, install Plotly via the terminal:
pip install plotlyOnce installed, you can create animated visualizations with just a few lines of code. The following example generates an animated horizontal bar chart showing the evolution of natural disasters over time:
import plotly.express as px<br>from vega_datasets import data<br>df = data.disasters()<br>df = df[df.Year > 1990]<br>fig = px.bar(df, y="Entity", x="Deaths", animation_frame="Year", orientation='h', range_x=[0, df.Deaths.max()], color="Entity")<br>fig.update_layout(width=1000, height=800, xaxis_showgrid=False, yaxis_showgrid=False, paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', title_text='Evolution of Natural Disasters', showlegend=False)<br>fig.update_xaxes(title_text='Number of Deaths')<br>fig.update_yaxes(title_text='')<br>fig.show()A similar approach creates an animated scatter plot of the Gapminder dataset, illustrating GDP per capita versus life expectancy over years:
import plotly.express as px<br>df = px.data.gapminder()<br>fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", size="pop", color="continent", hover_name="country", log_x=True, size_max=55, range_x=[100, 100000], range_y=[25, 90])<br>fig.update_layout(width=1000, height=800, xaxis_showgrid=False, yaxis_showgrid=False, paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)')<br>fig.show()The sunburst chart visualizes hierarchical group‑by results, allowing you to explore tip averages by gender, time, and day:
import plotly.graph_objects as go<br>import plotly.express as px<br>import pandas as pd<br>df = px.data.tips()<br>fig = go.Figure(go.Sunburst(labels=["Female", "Male", "Dinner", "Lunch", "Dinner ", "Lunch ", "Fri", "Sat"],<br> parents=["", "", "Female", "Female", "Male", "Male", "Dinner", "Dinner"],<br> values=np.append(np.append(df.groupby('sex').tip.mean().values, df.groupby(['sex','time']).tip.mean().values),<br> marker=dict(colors=px.colors.sequential.Emrld)))<br>fig.update_layout(paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', margin=dict(t=0,l=0,r=0,b=0), title_text='Tipping Habbits Per Gender, Time and Day')<br>fig.show()Parallel categories charts provide an interactive way to explore relationships among categorical variables, as shown with the movie dataset:
import plotly.express as px<br>from vega_datasets import data<br>import pandas as pd<br>df = data.movies()<br>df = df.dropna()<br>df['Genre_id'] = df.Major_Genre.factorize()[0]<br>fig = px.parallel_categories(df, dimensions=['MPAA_Rating','Creative_Type','Major_Genre'], color='Genre_id', color_continuous_scale=px.colors.sequential.Emrld)<br>fig.show()Parallel coordinates extend this idea to continuous variables, helping to spot outliers, clusters, and redundant dimensions:
import plotly.express as px<br>from vega_datasets import data<br>import pandas as pd<br>df = data.movies()<br>df = df.dropna()<br>df['Genre_id'] = df.Major_Genre.factorize()[0]<br>fig = px.parallel_coordinates(df, dimensions=['IMDB_Rating','IMDB_Votes','Production_Budget','Running_Time_min','US_Gross','Worldwide_Gross','US_DVD_Sales'], color='IMDB_Rating', color_continuous_scale=px.colors.sequential.Emrld)<br>fig.show()Finally, gauge and indicator charts are useful for KPI dashboards, combining numeric values with visual cues:
import plotly.graph_objects as go<br>fig = go.Figure(go.Indicator(domain={'x':[0,1],'y':[0,1]}, value=4.3, mode="gauge+number+delta", title={'text':'Success Metric'}, delta={'reference':3.9}, gauge={'bar':{'color':'lightgreen'},'axis':{'range':[None,5]},'steps':[{'range':[0,2.5],'color':'lightgray'},{'range':[2.5,4],'color':'gray'}]))<br>fig.show()The article demonstrates that with Plotly, a wide range of non‑traditional visualizations can be created quickly, making data stories more attractive and effective.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.