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

Conversation

Projects
None yet
3 participants
@konradjk
Copy link
Collaborator

commented Feb 5, 2019

No description provided.

@konradjk

This comment has been minimized.

Copy link
Collaborator Author

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

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 6, 2019

Collaborator

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

This comment has been minimized.

Copy link
@konradjk

konradjk Feb 6, 2019

Author Collaborator

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.

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 6, 2019

Collaborator

lower-case figure

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

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 6, 2019

Collaborator

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.

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 6, 2019

Collaborator

Add Examples section illustrating how the parameters are used

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 7, 2019

Collaborator

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}")

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 6, 2019

Collaborator

you mean, on the same table?

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 6, 2019

Collaborator

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())

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 6, 2019

Collaborator

is this the right indentation?

This comment has been minimized.

Copy link
@konradjk

konradjk Feb 6, 2019

Author Collaborator

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.

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 6, 2019

Collaborator

Could you more explanation (or a link) regarding how this is used

@jbloom22

This comment has been minimized.

Copy link
Collaborator

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))

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 6, 2019

Collaborator

why strings?

This comment has been minimized.

Copy link
@konradjk

konradjk Feb 6, 2019

Author Collaborator

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

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 6, 2019

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

addressed

konradjk added some commits Feb 6, 2019

@jbloom22
Copy link
Collaborator

left a comment

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,

This comment has been minimized.

Copy link
@jbloom22
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.

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 7, 2019

Collaborator

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.

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 7, 2019

Collaborator

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

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 7, 2019

Collaborator

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

This comment has been minimized.

Copy link
@jbloom22

jbloom22 Feb 7, 2019

Collaborator

"Compatible" rather than "Effective"?

addressed

@danking danking merged commit c3b1183 into hail-is:master Feb 8, 2019

1 check passed

hail-ci-0-1 successful build
Details

@konradjk konradjk deleted the konradjk:hist2d branch Feb 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.