Skip to content
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

Adding 2d histogram function #5249

Merged
merged 21 commits into from
Feb 8, 2019
Merged

Adding 2d histogram function #5249

merged 21 commits into from
Feb 8, 2019

Conversation

konradjk
Copy link
Collaborator

@konradjk konradjk commented Feb 5, 2019

No description provided.

@konradjk
Copy link
Collaborator Author

konradjk commented Feb 5, 2019

You're the lucky winner @jbloom22

Also, weird, the tests are failing, but in code I didn't write...

@@ -126,6 +127,147 @@ def cumulative_histogram(data, range=None, bins=50, legend=None, title=None, nor
return p


def set_font_size(p, font_size: str = "12pt"):
"""Set as many font sizes as possible in a bokeh figure
Copy link
Contributor

Choose a reason for hiding this comment

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

"Set all possible font sizes in a bokeh figure."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, I'm not 100% sure that these are all of the possible ones. Just the ones I've encountered so far. I'll make this a sub-function of the histogram2d one for now

Parameters
----------
p : :class:`bokeh.plotting.figure.Figure`
Input Figure.
Copy link
Contributor

Choose a reason for hiding this comment

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

lower-case figure

p : :class:`bokeh.plotting.figure.Figure`
Input Figure.
font_size : str
String of font size in points (e.g. "12pt").
Copy link
Contributor

Choose a reason for hiding this comment

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

single-quote more pythonic?

plot_title='2-D histogram', plot_width=600, plot_height=600, font_size='7pt',
colors=bokeh.palettes.all_palettes['Blues'][7][::-1]):
"""Plot a 2-D histogram of x vs y, which are NumericExpressions from a Table.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add Examples section illustrating how the parameters are used

Copy link
Contributor

Choose a reason for hiding this comment

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

We usually give examples in a section that starts with:

Examples
---------

e.g.
https://hail.is/docs/0.2/methods/impex.html#hail.methods.import_bgen

check_row_indexed('histogram_2d', x)
check_row_indexed('histogram_2d', y)
if source != y_source:
raise ValueError(f"histogram_2d expects two expressions of 'Table', found {source} and {y_source}")
Copy link
Contributor

Choose a reason for hiding this comment

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

you mean, on the same table?

Copy link
Contributor

Choose a reason for hiding this comment

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

move this check up a couple lines


grouped_ht = source.group_by(
x=hail.str(x_levels.find(lambda w: x >= w)), y=hail.str(y_levels.find(lambda w: y >= w))
).aggregate(c=hail.agg.count())
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 the right indentation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My PyCharm claims it is but happy to change if there's another preferred one

font_size : str
String of font size in points (default "7pt").
colors : List[str]
List of hex colors from low to high.
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 more explanation (or a link) regarding how this is used

@jbloom22
Copy link
Contributor

jbloom22 commented Feb 6, 2019

I think if there are elements outside the range you should warn

y_levels = hail.literal(list(frange(y_range[0], y_range[1], y_spacing))[::-1])

grouped_ht = source.group_by(
x=hail.str(x_levels.find(lambda w: x >= w)), y=hail.str(y_levels.find(lambda w: y >= w))
Copy link
Contributor

Choose a reason for hiding this comment

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

why strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a little funky. Bokeh needs them to be strings in order to correctly plot them as discrete values rather than a continuous scale.

@konradjk
Copy link
Collaborator Author

konradjk commented Feb 6, 2019

Also willing to discuss a default color palette - anyone want to have a principled discussion about some nice defaults?

Copy link
Contributor

@jbloom22 jbloom22 left a comment

Choose a reason for hiding this comment

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

Just a few small tweaks, otherwise looks great!

bins=int, x_bins=nullable(int), y_bins=nullable(int),
plot_title=nullable(str), plot_width=int, plot_height=int,
font_size=str, colors=sequenceof(str))
def histogram_2d(x, y, x_range=None, y_range=None, bins=40, x_bins=None, y_bins=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

def histogram_2d(x, y, x_range=None, y_range=None, bins=40, x_bins=None, y_bins=None,
plot_title='2-D histogram', plot_width=600, plot_height=600, font_size='7pt',
colors=bokeh.palettes.all_palettes['Blues'][7][::-1]):
"""Plot a 2-D histogram.
Copy link
Contributor

Choose a reason for hiding this comment

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

Plot a two-dimensional histogram.

plot_title='2-D histogram', plot_width=600, plot_height=600, font_size='7pt',
colors=bokeh.palettes.all_palettes['Blues'][7][::-1]):
"""Plot a 2-D histogram of x vs y, which are NumericExpressions from a Table.

Copy link
Contributor

Choose a reason for hiding this comment

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

We usually give examples in a section that starts with:

Examples
---------

e.g.
https://hail.is/docs/0.2/methods/impex.html#hail.methods.import_bgen

Number of bins on x-axis, will override ``bins`` if provided.
y_bins : int
Number of bins on y-axis, will override ``bins`` if provided.
plot_width : int
Copy link
Contributor

Choose a reason for hiding this comment

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

why prefix these three with plot?

String of font size in points (default '7pt').
colors : List[str]
List of colors (hex codes, or strings as described
`here <https://bokeh.pydata.org/en/latest/docs/reference/colors.html>`__). Effective with one of the many
Copy link
Contributor

Choose a reason for hiding this comment

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

"Compatible" rather than "Effective"?

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.

None yet

3 participants