Skip to content

Files

Latest commit

5194841 · Jun 20, 2021

History

History
67 lines (60 loc) · 1.59 KB

group-by.md

File metadata and controls

67 lines (60 loc) · 1.59 KB
jupyter
jupytext kernelspec language_info plotly
notebook_metadata_filter text_representation
all
extension format_name format_version jupytext_version
.md
markdown
1.1
1.1.7
display_name language name
Python 3
python
python3
codemirror_mode file_extension mimetype name nbconvert_exporter pygments_lexer version
name version
ipython
3
.py
text/x-python
python
python
ipython3
3.6.5
description display_as language layout name order page_type permalink thumbnail
How to use group by in Python with Plotly.
transforms
python
base
Group By
2
example_index
python/group-by/
thumbnail/groupby.jpg

Note transforms are deprecated in plotly v5 and will be removed in a future version.

Basic Example

import plotly.io as pio

subject = ['Moe','Larry','Curly','Moe','Larry','Curly','Moe','Larry','Curly','Moe','Larry','Curly']
score = [1,6,2,8,2,9,4,5,1,5,2,8]

data = [dict(
  type = 'scatter',
  x = subject,
  y = score,
  mode = 'markers',
  transforms = [dict(
    type = 'groupby',
    groups = subject,
    styles = [
        dict(target = 'Moe', value = dict(marker = dict(color = 'blue'))),
        dict(target = 'Larry', value = dict(marker = dict(color = 'red'))),
        dict(target = 'Curly', value = dict(marker = dict(color = 'black')))
    ]
  )]
)]

fig_dict = dict(data=data)
pio.show(fig_dict, validate=False)

Reference

See https://plotly.com/python/reference/ for more information and chart attribute options!