Open In App

Treemap using graph_objects class in plotly

Last Updated : 30 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library.

Treemap using graph_objects class

Treemapping is a data visualization procedure which can be used to demonstrate graded data using enclosed rectangles. Data is organized as branches and sub_branches by representing using rectangles, dimensions and plot color.Tree map chart helps in distinguishing the categories between data values apparently.

Syntax: class plotly.graph_objects.Treemap(arg=None, branchvalues=None, count=None, customdata=None, hoverinfo=None, **kwargs)

Parameters:

arg: dict of properties compatible with this constructor or an instance of plotly.graph_objects.Treemap

branchvalues: Determines how the items in values are summed.

count:  Determines default for values when it is not provided, by inferring a 1 for each of the “leaves” and/or “branches”, otherwise 0.

customdata:  Assigns extra data each datum. This may be useful when listening to hover, click and selection events. Note that, “scatter” traces also appends customdata items in the markers DOM elements

hoverinfo: Determines which trace information appear on hover. If none or skip are set, no information is displayed upon hovering. But, if none is set, click and hover events are still fired.

Example:

Python3




import plotly.graph_objects as go
  
fig = go.Figure(go.Treemap(
    labels = ["A", "B", "C", "D", "E"],
    parents = ["", "A", "B", "C", "A"] 
))
  
fig.show()


Output:

Set Color of Treemap Sectors

To change the color sector in treemap there are three different ways:

  • marker.colors
  • colorway
  • colorscale

Example:

Python3




import plotly.graph_objects as go
  
fig = go.Figure(go.Treemap(
    labels = ["A", "B", "C", "D", "E"],
    parents = ["", "A", "B", "C", "A"],
    marker_colors = ["blue", "pink", "red"
                 "royalblue", "lightgray", ]
))
  
fig.show()


Output:

Changing text fontsize

In plotly, the labels can be remain of same size by using uniformtext  layout parameter.The font size are set by minsize attributes, and mode attributes are set for labels cannot fit with the desired fontsize: either hide them or show them with overflow.

Python3




import plotly.graph_objects as go
  
fig = go.Figure(go.Treemap(
    labels = ["A", "B", "C", "D", "E"],
    parents = ["", "A", "B", "C", "A"],
marker_colors = ["blue", "pink"]
))
  
fig.update_layout(uniformtext = dict(minsize = 15,
                                   mode ='hide'))
  
fig.show()


Output:



Similar Reads

Box plot in Plotly using graph_objects class
Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. Box plot using graph objects class If Plotly Exp
4 min read
Histograms in Plotly using graph_objects class
Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. Histogram using graph_objects class Plotly provi
9 min read
Scatter plot in Plotly using graph_objects class
Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. Scatter plot using graph_objects class Scatter p
3 min read
3D Scatter Plot using graph_objects Class in Plotly-Python
Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. Scatter plot using graph_objects class If a plot
2 min read
Sunburst Plot using graph_objects class in plotly
Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. Sunburst Plot using graph_objects class If Plotl
3 min read
Create Heatmaps using graph_objects class in Plotly
A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. Heatmaps using graph_objects A heatmap is a tw
2 min read
Treemap using Plotly in Python
Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. Treemap in Plotly Treemap in plotly.express is c
3 min read
How to hide legend with Plotly Express and Plotly in Python?
In this article, we will learn How to hide legend with Plotly Express and Plotly. Here we will discuss two different methods for hiding legend in plotly and plotly express, using two different examples for each to make it more clear. Syntax: For legend: fig.update_traces(showlegend=False)fig.update(layout_showlegend=False) Example 1: In this exampl
2 min read
Plotly - How to show legend in single-trace scatterplot with plotly express?
In this article let's see how to show legend in single-trace scatterplot with plotly express. A 'trace' is the name given to each plot inside the chart. Generally in plotly legend is not visible for single trace scatter plots. Example: In the below, example packages and data are imported and a single trace scatter plot is plotted using px.scatter()
1 min read
How to create a Ternary Overlay using Plotly?
A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library Creating Ternary Scatter Plot A ternary scatter
2 min read
Practice Tags :