Embed Interactive charts in Medium/Websites using Plotly and Chartstudio with Python | by Syam Kakarla | Towards Data Science

There is no such thing as information overload. There is only a bad design. — Edward Tufte
We all know a picture is worth a thousand words, data visualization is the visual summary of the information that makes it easier to understand/identify patterns and trends instead of looking at thousands of rows in spreadsheets. A good data visualization place the meaning of complex datasets in a precise and concise way. An interactive data visualization makes it even easier to understand and find insights from the data.
This article covers creating different interactive plots using Plotly and embedding interactive data visualizations in Medium and websites using Chartstudio.
Let’s get started✨
Chartstudio is a platform that hosts your interactive plots/charts in the cloud. It has also developed open-source graphing Application Programming Interface (API) libraries for Python, R, MATLAB, Javascript, and other computer programming languages. The important features of Plotly and chartstudio are:
It produces interactive graphs/charts.
The graphs are stored in JavaScript Object Notation (JSON) data format so that they can be read using scripts of other programming languages such as R, Julia, MATLAB, etc.
Graphs can be exported in various raster as well as vector image formats
Let’s see how to connect with chartstudio,
Signup to chartstudio platform with credentials like Google, Facebook, Github, e.t.c.Go to Settings > API Keys, save the username and API Key.
Signup to chartstudio platform with credentials like Google, Facebook, Github, e.t.c.
Go to Settings > API Keys, save the username and API Key.
The below code servers the purpose to connect with chartstudio using Python. chartstudio.tools.set_credentials_file takes username and api key to connect with the platform.
To embed interactive plots on medium/Websites, we need to store the interactive plots using chartstudio. Let’s see how to save the interactive plots using the Chartstusio Python API.
In this article, we are going to use gapminder dataset that contains data that includes one year of numerous country-level indicators of health, wealth, and development.
The below code plots a pie chart of the population of Asia in 2007 w.r.t to each country. The plotly.express.pie() method is used to plot the chart.
After creating the plot, we have to save it into the chartstudio cloud. To do that we use chart_studio.plotly.plot() method that talked figure object, filename, and other parameters. After executing the below line of code, it results in a hyperlink that can be used to embed in either Medium or other websites.
py.plot(pop, filename = 'Population_Asia', auto_open=True)# Outputhttps://plotly.com/~syamkakarla98/41/
Paste the link in Medium to embed the interactive plots/charts.
Not only Pie charts but you can also embed 3D Plots, Box plots, Distribution Plots, Multidimensional Plots, Tile Maps, e.t.c.
You can also create classification charts using Plotly and embed them using chartstudio. the below example shows how to create a simple KNN classification chart for the synthetic circle's dataset from sklearn.datasets and the resultant figure is shown below.
This article helps readers to create interactive plots and embedding them in either Medium or other Websites using Plotly and Chartstudio API with Python.