Skip to content

Treemap python #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 17, 2019
Merged

Treemap python #138

merged 7 commits into from
Oct 17, 2019

Conversation

Mahdis-z
Copy link
Contributor

Doc upgrade checklist:

  • random seed is set if using random data
  • file has been moved from unconverted/x/y.md to x/y.md
  • old boilerplate at top and bottom of file has been removed
  • Every example is independently runnable and is optimized for short line count
  • no more plot() or iplot()
  • graph_objs has been renamed to graph_objects
  • fig = <something> call is high up in each example
  • minimal creation of intermediate trace objects
  • liberal use of add_trace and update_layout
  • fig.show() at the end of each example
  • px example at the top if appropriate
  • minimize usage of hex codes for colors in favour of those in https://github.com/plotly/plotly.py-docs/issues/14


### Basic Treemap

Treemap chart visualize hierarchical data using nested rectangles. Same as [Sunburst](https://plot.ly/python/sunburst-charts/) the hierarchy is defined by [labels](https://plot.ly/python/reference/#treemap-labels) and [parents]((https://plot.ly/python/reference/#treemap-parents)) attributes. [count](https://plot.ly/python/reference/#treemap-count) attribute allows counting the numbers of leaves, branches or both when values array is not provided.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a link to Wikipedia https://en.wikipedia.org/wiki/Treemapping

fig.show()
```

### Advance Treemap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treemap with several nested layers

(this code is actually not very complex, so I suggest to drop the "advanced")


### Advance Treemap

The following example uses hierarchical data that includes layers and grouping. Treemap and [Sunburst](https://plot.ly/python/sunburst-charts/) charts reveal indights into the data, and the format of your hierarchical data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indights --> insights


fig = go.Figure()

fig.add_trace(go.Treemap(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use make_subplots here instead of domain? I think we're trying to push make_subplots as the preferred method to create subplots (and then you can add subtitles for example).


### Set Different Attributes in Treemap

This example uses the following attributs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attributes


This example uses the following attributs:

1. [values](https://plot.ly/python/reference/#treemap-values): sets the values associated with each of the sunburst sectors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with each of the sectors (remove suburst)

```python
import plotly.graph_objects as go

fig = go.Figure(go.Treemap(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as below, could use make_subplots?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

### Basic Treemap

Treemap chart visualize hierarchical data using nested rectangles. Same as [Sunburst](https://plot.ly/python/sunburst-charts/) the hierarchy is defined by [labels](https://plot.ly/python/reference/#treemap-labels) and [parents]((https://plot.ly/python/reference/#treemap-parents)) attributes. [count](https://plot.ly/python/reference/#treemap-count) attribute allows counting the numbers of leaves, branches or both when values array is not provided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain here how to interact with the treemap chart: click on one sector to zoom (mention the pathbar), and double-click to zoom out one level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I add how to zoom in with click... to zoom out we basically use 'pathbar'.. double click is doing the same thing that click does.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me (Chrome) double clicking zooms out one level, is it the same for you?

import plotly.graph_objects as go

fig = go.Figure(go.Treemap(
labels = ["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define labels and parents variables before defining the traces to show it's the same data used for the two traces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To kinda show the possibility of plotting Treemap with defining only these 2 attributes, make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no sorry, this is not what I meant: since it's the same values for the two traces for labels and parents I was suggesting to define variables to hold these values to reduce code duplication and to show what is similar in the two traces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

marker = {"line": {"width": 2}},
pathbar = {"visible": False}))

fig.update_layout(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with subplots you could use subtitles here which would be more readable

@emmanuelle
Copy link
Contributor

Is it possible to add an example showing how to control the color of Treemap sectors? (From a rapid scroll through the docstring I did not find the answer so this would be all the more useful ;-))

```python
import plotly.graph_objects as go

fig = go.Figure()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we have one single trace we prefer the more compact syntax

fig = go.Figure(go.Treemap(...))

@emmanuelle
Copy link
Contributor

About using make_subplots, did you use domain instead because make_subplots is more difficult to use for non-Cartesian axes?

pygments_lexer: ipython3
version: 3.7.3
plotly:
description: How to make Treemap Charts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. with plotly

order: 14
page_type: u-guide
permalink: python/treemap-charts/
thumbnail: thumbnail/treemap.png
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a new thumbnail or the old one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new thumbnail


### Basic Treemap

Treemap chart visualize hierarchical data using nested rectangles. Same as [Sunburst](https://plot.ly/python/sunburst-charts/) the hierarchy is defined by [labels](https://plot.ly/python/reference/#treemap-labels) and [parents]((https://plot.ly/python/reference/#treemap-parents)) attributes. [count](https://plot.ly/python/reference/#treemap-count) attribute allows counting the numbers of leaves, branches or both when values array is not provided.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chart --> charts
Same as -- As for

I would leave the explanation about count for later in the tutorial since it's not used in the example just below

name: Treemap Charts
order: 14
page_type: u-guide
permalink: python/treemap-charts/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This permalink should be the same as the file you're deleting in the other PR, so we inherit all the traffic from the previous page!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and the filename should match)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, it would be best if the deletion and upgrade were in the same PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This permalink should be the same as the file you're deleting in the other PR, so we inherit all the traffic from the previous page!

good point, I changed it to be similar to other charts name!

@emmanuelle
Copy link
Contributor

Nicolas showed me that the color is controlled by marker.colors.

@emmanuelle
Copy link
Contributor

One thing which you might do another time is to do a git mv treemap-chart.md treemap.md so that we would still see the comments in the file you've updated :-). Can you also do git rm treemap-chart.md now that it's not needed?

parents = parents,
values = [10, 14, 12, 10, 2, 6, 6, 1, 4],
textinfo = "label+value+percent parent+percent entry+percent root",
pathbar = {"visible": False}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a smart trick to disable the pathbar because of the overflow but the pathbar is super useful for navigation. What I tried is adding a blank line in the titles like branchvalues: <b>remainder</b><br> <br>', a bit ugly but it does the trick (you can add a comment in the code cell to explain that it's a workaround for now)

fig.show()
```

### Set Color of Sectors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set Color of Treemap Sectors

(I think we want to repeat the chart name as much as possible for search engines)


### Set Color of Sectors

There are three different ways to change the color of the sectors in Treemap:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice examples about colors, thanks for adding them! I would never have found the 3 ways myself 😆

fig = go.Figure(go.Treemap(
labels = labels,
parents = parents,
marker = {'colors': ["pink", "royalblue", "lightgray", "purple", "cyan", "lightgray", "lightblue"]}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very minor style remark, but can you use the shorter syntax marker_colors here? We're trying to push the magic underscore as much as possible :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point

labels = labels,
values = values,
parents = parents,
marker = {"colorscale": "Blues"}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marker_colorscale for more magic underscore :-)

### Nested Layers in Treemap

The following example uses hierarchical data that includes layers and grouping. Treemap and [Sunburst](https://plot.ly/python/sunburst-charts/) charts reveal insights into the data, and the format of your hierarchical data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a sentence about maxdepth here?

@emmanuelle
Copy link
Contributor

Thanks for the update! I left a couple of comments and after this we should be good to go :-)

@emmanuelle
Copy link
Contributor

Could you also update the plotly.py version in the requirements.txt with the new release to make CircleCI happy?

@emmanuelle
Copy link
Contributor

💃 once the CI is happy (bumping up plotly.py in requirements.txt should do the job I hope)

@emmanuelle
Copy link
Contributor

💃 !

@Mahdis-z Mahdis-z merged commit 7177840 into master Oct 17, 2019
@Mahdis-z Mahdis-z deleted the _treemap_python branch October 17, 2019 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants