Package Structure of Plotly

There are three main modules in Plotly. They are:

  • plotly.plotly
  • plotly.graph.objects
  • plotly.tools

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. Consider the below example for better understanding.

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, 3], y=[1, 2, 3])
 
# printing the figure instance
print(fig)


Output:

Figure({
'data': [{'hovertemplate': 'x=%{x}<br>y=%{y}<extra></extra>',
'legendgroup': '',
'line': {'color': '#636efa', 'dash': 'solid'},
'marker': {'symbol': 'circle'},
'mode': 'lines',
'name': '',
'orientation': 'v',
'showlegend': False,
'type': 'scatter',
'x': array([1, 2, 3]),
'xaxis': 'x',
'y': array([1, 2, 3]),
'yaxis': 'y'}],
'layout': {'legend': {'tracegroupgap': 0},
'margin': {'t': 60},
'template': '...',
'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0], 'title': {'text': 'x'}},
'yaxis': {'anchor': 'x', 'domain': [0.0, 1.0], 'title': {'text': 'y'}}}
})

Figures are represented as trees where the root node has three top layer attributes – data, layout, and frames and the named nodes called ‘attributes’. Consider the above example, layout.legend is a nested dictionary where the legend is the key inside the dictionary whose value is also a dictionary.  

plotly.tools module contains various tools in the forms of the functions that can enhance the Plotly experience. 

Plotly tutorial

Plotly library in Python is an open-source library that can be used for data visualization and understanding data simply and easily. Plotly supports various types of plots like line charts, scatter plots, histograms, box plots, etc. So you all must be wondering why Plotly is over other visualization tools or libraries. So here are some reasons :

  • Plotly has hover tool capabilities that allow us to detect any outliers or anomalies in a large number of data points.
  • It is visually attractive and can be accepted by a wide range of audiences.
  • Plotly generally allows us endless customization of our graphs and makes our plot more meaningful and understandable for others.

This tutorial aims at providing you the insight about Plotly with the help of the huge dataset explaining the Plotly from basics to advance and covering all the popularly used charts.

Table of Content

  • How to install Plotly?
  • Package Structure of Plotly
  • Getting Started
  • Creating Different Types of Charts
  • Heatmaps
  • Error Bars
  • 3D Line Plots
  • 3D Scatter Plot Plotly
  • 3D Surface Plots
  • Interacting with the Plots
  • Adding Buttons to the Plot
  • Creating Sliders and Selectors to the Plot
  • More Plots using Plotly

Similar Reads

How to install Plotly?

Before installing Plotly in system, you need to install pip in your system, Refer to –...

Package Structure of Plotly

There are three main modules in Plotly. They are:...

Getting Started

...

Creating Different Types of Charts

After learning the installation and basic structure of the Plotly, let’s create a simple plot using the pre-defined data sets defined by the plotly....

Heatmaps

...

Error Bars

With plotly we can create more than 40 charts and every plot can be created using the plotly.express and plotly.graph_objects class. Let’s see some commonly used charts with the help of Plotly....

3D Line Plots

...

3D Scatter Plot Plotly

...

3D Surface Plots

...

Interacting with the Plots

...

Adding Buttons to the Plot

...

Creating Sliders and Selectors to the Plot

...

More Plots using Plotly

...

Contact Us