Skip to content

added histogram to facet_grid #776

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 18 commits into from
Jul 1, 2017
Merged

added histogram to facet_grid #776

merged 18 commits into from
Jul 1, 2017

Conversation

Kully
Copy link
Contributor

@Kully Kully commented Jun 20, 2017

No description provided.

@Kully
Copy link
Contributor Author

Kully commented Jun 20, 2017

screen shot 2017-06-20 at 12 38 26 pm

@Kully
Copy link
Contributor Author

Kully commented Jun 20, 2017

@chriddyp @cldougl
would like a review when tests pass

CHANGELOG.md Outdated
@@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- `.create_facet_grid` now supports histogram traces.
Copy link
Member

Choose a reason for hiding this comment

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

maybe figure_factory.create_facet_grid just to be super clear

@cldougl
Copy link
Member

cldougl commented Jun 20, 2017

just tried putting hist in one of the docstring examples and it's rendered a bit weird and needs to be autoscaled:

import plotly.plotly as py
import plotly.figure_factory as ff  

import pandas as pd
mpg = pd.read_table('https://raw.githubusercontent.com/plotly/datasets/master/mpg_2017.txt')

fig = ff.create_facet_grid(mpg, x='displ', y='cty', facet_col='cyl', trace_type='histogram')
py.iplot(fig, filename='facet_grid_mpg_one_way_facet')

hist

)

temp_trace = 'scatter' if (trace_type == 'histogram') else trace_type
Copy link
Member

Choose a reason for hiding this comment

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

since this renders the trace as scatter first, the histogram attributes can't be passed. For example:

tips = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/tips.csv')

fig = ff.create_facet_grid(
    tips,
    x='total_bill',
    y='tip',
    trace_type='histogram',
    histfunc='sum',
    facet_row='sex',
    facet_col='smoker'
)
py.iplot(fig, filename='facet_grid_tips_sequential_colors')

fails with:
screen shot 2017-06-20 at 2 08 42 pm

@Kully
Copy link
Contributor Author

Kully commented Jun 20, 2017

Note: going to add lines to histogram for aesthetics

@Kully
Copy link
Contributor Author

Kully commented Jun 23, 2017

@cldougl tests finally passed. good to merge?

@cldougl
Copy link
Member

cldougl commented Jun 26, 2017

I'll take another look this afternoon @Kully
can you fix the changelog conflicts?

@@ -25,6 +25,7 @@
THRES_FOR_FLIPPED_FACET_TITLES = 10
GRID_WIDTH = 1

VALID_TRACE_TYPES = ['scatter', 'scattergl', 'histogram']
Copy link
Member

Choose a reason for hiding this comment

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

technically other types too though, right? I think that box, histogram2d, and bar might work now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember not liking the look of box or bar - it was very squashed up, but perhaps it was the dataset

@@ -189,18 +190,22 @@ def _facet_grid_color_categorical(df, x, y, facet_row, facet_col, color_name,
if not facet_row and not facet_col:
color_groups = list(df.groupby(color_name))
for group in color_groups:
trace = graph_objs.Scatter(
trace = dict(
x=group[1][x],
y=group[1][y],
Copy link
Member

Choose a reason for hiding this comment

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

I'm having a hard time understanding what happens when the histogram mode sets both x and y here. Shouldn't only one of them be set?

Copy link
Member

Choose a reason for hiding this comment

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

Or is just the other variable ignored?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, or the user just doesn't supply the y variable when setting it? Like

FF.facet_grid(df, x='categorial-column', facet_col='another-column', trace_type='histogram')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You found an oversight in my design.

Originally this was meant for just scatter, so I was forcing x and y. I'm going to try not forcing x and y and putting df[x] and df[y] in the trace dictionary depending on what the user provides

@Kully
Copy link
Contributor Author

Kully commented Jun 27, 2017

@chriddyp We got some nice variety going:

screen shot 2017-06-26 at 6 39 38 pm

screen shot 2017-06-26 at 6 40 04 pm

screen shot 2017-06-26 at 6 40 32 pm

@Kully
Copy link
Contributor Author

Kully commented Jun 29, 2017

@cldougl Can you give this one quick review today? I'm trying to get it merged today and the pip package updated so I can finish documentation by the end of the week.

Thank you 😄

@cldougl
Copy link
Member

cldougl commented Jun 29, 2017

@Kully is it possible to change the color of the markers?
Like:

import plotly.plotly as py
import plotly.figure_factory as ff

import pandas as pd

mpg = pd.read_table('https://raw.githubusercontent.com/plotly/datasets/master/mpg_2017.txt')

fig = ff.create_facet_grid(
    mpg,
    x='displ',
    y='cty',
    facet_row='drv',
    facet_col='cyl',
    marker=dict(color='rgba(255, 182, 193, .9)')
)
py.iplot(fig, filename='facet_grid_mpg_two_way_facet')


fig = ff.create_facet_grid(
mtcars,
x='wt',
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this example only have an x or a y?

type=trace_type,
marker=dict(
color=marker_color,
**kwargs_marker
line=kwargs_marker['line'],
#opacity=kwargs_marker['opacity'],
Copy link
Member

Choose a reason for hiding this comment

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

should this be commented out?

@@ -25,6 +25,7 @@
THRES_FOR_FLIPPED_FACET_TITLES = 10
GRID_WIDTH = 1

VALID_TRACE_TYPES = ['scatter', 'scattergl', 'histogram', 'bar', 'box']
Copy link
Member

Choose a reason for hiding this comment

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

are we planning on adding histogram2d as well (#776 (review)) ?

Copy link
Member

Choose a reason for hiding this comment

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

and histogram2dcontour

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since marker is not a valid key in facet grid, I vote that these trace types get moved into another PR/Issue. It would require a large reworking of the code, so I think we should move it to another issue so we can get this merged so the documentation can go up this week.

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok w/ doing those in a different pr

@cldougl
Copy link
Member

cldougl commented Jun 29, 2017

screen shot 2017-06-29 at 1 58 48 pm

looks like the histogram labels will overlap due to how the ticks are labeled at the bin edges. Do you think there's something stylistically we could do to avoid this such as increasing the gap between when the histogram trace is used?

@chriddyp
Copy link
Member

looks good to me! 💃 from me once @cldougl 's comments are addressed

@Kully
Copy link
Contributor Author

Kully commented Jun 29, 2017

looks like the histogram labels will overlap due to how the ticks are labeled at the bin edges. Do you think there's something stylistically we could do to avoid this such as increasing the gap between when the histogram trace is used?

Yeah, I think that would be a good idea

@cldougl
Copy link
Member

cldougl commented Jun 30, 2017

💃 good for me too
(lmk if you want me to fix the changelog conflict @Kully )

@Kully
Copy link
Contributor Author

Kully commented Jun 30, 2017

💃 good for me too
(lmk if you want me to fix the changelog conflict @Kully )

just did

@Kully Kully merged commit 17b27dd into master Jul 1, 2017
@Kully Kully deleted the add-hist-to-facet branch July 1, 2017 11:19
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