-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Added _make_colorscale method and 2D Density Plot #518
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
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f051573
Added _make_colorscale method and 2D Density Plot
Kully 7f95dcf
Updated schema
Kully 8cf26dc
Renaming variables and optimizing _make_linear_colorscale
Kully d7cf2de
Added tests to 2d_density
Kully 886efa6
Fixed Spacing in Test
Kully 4d88ea7
Changed ver # to '1.12.3'
Kully 7044922
Update default schema
Kully File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1477,30 +1477,26 @@ class FigureFactory(object): | |
""" | ||
|
||
@staticmethod | ||
def _make_colorscale(colors): | ||
def _make_linear_colorscale(colors): | ||
""" | ||
Makes a list of colors into a colorscale-acceptable form | ||
|
||
For documentation regarding to the form of the output, see | ||
https://plot.ly/python/reference/#mesh3d-colorscale | ||
""" | ||
colorscale = [] | ||
diff = 1./(len(colors) - 1) | ||
|
||
for j in range(len(colors)): | ||
colorscale.append([j * diff, colors[j]]) | ||
return colorscale | ||
scale = 1./(len(colors) - 1) | ||
return[[i * scale, color] for i, color in enumerate(colors)] | ||
|
||
@staticmethod | ||
def create_2D_density(x, y, colorscale='Earth', ncontours=20, | ||
hist_color=(0, 0, 0.5), pt_color=(0, 0, 0.5), | ||
pt_size=2, height=600, width=600): | ||
hist_color=(0, 0, 0.5), point_color=(0, 0, 0.5), | ||
point_size=2, height=600, width=600): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks 😺 |
||
""" | ||
Returns figure for a 2D density plot | ||
|
||
:param (list) x: x-axis data for plot generation | ||
:param (list) y: y-axis data for plot generation | ||
:param (str|tuple|list) colormap: either a plotly scale name, an rgb | ||
:param (str|tuple|list) colorscale: either a plotly scale name, an rgb | ||
or hex color, a color tuple or a list or tuple of colors. An rgb | ||
color is of the form 'rgb(x, y, z)' where x, y, z belong to the | ||
interval [0, 255] and a color tuple is a tuple of the form | ||
|
@@ -1509,8 +1505,8 @@ def create_2D_density(x, y, colorscale='Earth', ncontours=20, | |
members. | ||
:param (int) ncontours: the number of 2D contours to draw on the plot | ||
:param (str) hist_color: the color of the plotted histograms | ||
:param (str) pt_color: the color of the scatter points | ||
:param (str) pt_size: the color of the scatter points | ||
:param (str) point_color: the color of the scatter points | ||
:param (str) point_size: the color of the scatter points | ||
:param (float) height: the height of the chart | ||
:param (float) width: the width of the chart | ||
|
||
|
@@ -1547,25 +1543,26 @@ def create_2D_density(x, y, colorscale='Earth', ncontours=20, | |
|
||
# Create a figure | ||
fig = FF.create_2D_density( | ||
x, y, colorscale=colorscale, hist_color='rgb(255, 237, 222)', pt_size=3) | ||
x, y, colorscale=colorscale, | ||
hist_color='rgb(255, 237, 222)', point_size=3) | ||
|
||
# Plot the data | ||
py.iplot(fig, filename='use-parameters') | ||
``` | ||
""" | ||
from plotly.graph_objs import graph_objs | ||
colorscale = FigureFactory._validate_colors(colorscale, 'rgb') | ||
colorscale = FigureFactory._make_colorscale(colorscale) | ||
colorscale = FigureFactory._make_linear_colorscale(colorscale) | ||
|
||
# validate hist_color and pt_color | ||
# validate hist_color and point_color | ||
hist_color = FigureFactory._validate_colors(hist_color, 'rgb') | ||
pt_color = FigureFactory._validate_colors(pt_color, 'rgb') | ||
point_color = FigureFactory._validate_colors(point_color, 'rgb') | ||
|
||
trace1 = graph_objs.Scatter( | ||
x=x, y=y, mode='markers', name='points', | ||
marker=dict( | ||
color=pt_color[0], | ||
size=pt_size, | ||
color=point_color[0], | ||
size=point_size, | ||
opacity=0.4 | ||
) | ||
) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍