Overview of Plotly Package Structure
in Plotly, there are three main modules –
- plotly.plotly acts as the interface between the local machine and Plotly. It contains functions that require a response from Plotly’s server.
- plotly.graph_objects module contains the objects (Figure, layout, data, and the definition of the plots like scatter plot, line chart) that are responsible for creating the plots. The Figure can be represented either as dict or instances of plotly.graph_objects.Figure and these are serialized as JSON before it gets passed to plotly.js. Figures are represented as trees where the root node has three top layer attributes – data, layout, and frames and the named nodes called ‘attributes’.
Note: plotly.express module can create the entire Figure at once. It uses the graph_objects internally and returns the graph_objects.Figure instance.
Example:
Python3
import plotly.express as px # Creating the Figure instance fig = px.line(x = [ 1 , 2 ], y = [ 3 , 4 ]) # printing the figure instance print (fig) |
Output:
- plotly.tools module contains various tools in the forms of the functions that can enhance the Plotly experience.
After going through the basics of plotly let’s see how to create some basic charts using plotly.
Using Plotly for Interactive Data Visualization in Python
Plotly is an open-source module of Python which is used for data visualization and supports various graphs like line charts, scatter plots, bar charts, histograms, area plot, etc. In this article, we will see how to plot a basic chart with plotly and also how to make a plot interactive. But before starting you might be wondering why there is a need to learn plotly, so let’s have a look at it.