avatarSyam Kakarla

Summary

The website content explains how to create and embed interactive data visualizations in Medium articles and websites using Plotly and Chartstudio with Python.

Abstract

The article provides a comprehensive guide on using Plotly and Chartstudio to generate interactive charts and embed them into web platforms such as Medium. It emphasizes the importance of data visualization in making complex datasets accessible and understandable. The author walks readers through connecting to Chartstudio, creating various interactive plots like pie charts and classification plots, and saving these plots to the cloud for easy embedding into web content. The process involves signing up for Chartstudio, obtaining API keys, utilizing Plotly's Python library to create the charts, and then using Chartstudio's Python API to save and retrieve hyperlinks for embedding. The article also showcases the versatility of Plotly and Chartstudio by demonstrating the embedding of 3D plots, box plots, distribution plots, multidimensional plots, and tile maps. Additionally, the author provides references and links to further resources and related articles on topics like satellite imagery analysis, hyperspectral image analysis, and PySpark.

Opinions

  • The author quotes Edward Tufte, suggesting that "information overload" is a design problem rather than an inherent issue with data, implying that good design is crucial in data visualization.
  • There is a clear endorsement of interactive data visualizations as a means to enhance understanding and uncover insights from data, indicating that static visualizations are less effective.
  • The author positively promotes Plotly and Chartstudio, highlighting their ability to produce interactive graphs, support for various data formats like JSON, and the capability to export graphs in multiple image formats.
  • The author seems to value practicality, providing step-by-step instructions and code examples to facilitate the learning process for readers.
  • By offering additional reading materials and tutorials, the author suggests that there is significant value in exploring related data science topics and tools, encouraging continuous learning in the field.

Data Science | Data Visualization

Embed Interactive charts in Medium/Websites using Plotly and Chartstudio with Python

Embed your interactive plots in Medium, Webpages, and other platforms using Plotly and Chartstudio

Photo by William Iven on Unsplash

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✨

Connect with Chartstudio

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,

  1. Signup to chartstudio platform with credentials like Google, Facebook, Github, e.t.c.
  2. 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.

Embed Charts

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.

Pie chart

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)
# Output
https://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.

Classification Plots

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.

Conclusion

This article helps readers to create interactive plots and embedding them in either Medium or other Websites using Plotly and Chartstudio API with Python.

More from Author

References

Data Science
Data Visualization
Data Analysis
Python
Programming
Recommended from ReadMedium
avatarTechnocrat
Using Streamlit for UI

32 min read