-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Update VolcanoPlot props #554
Changes from all commits
0aec15d
b2f6506
712dbaa
52f05e5
bae0210
e36d4b6
0779b53
fef41e4
16bc23f
6f05a3b
c0ed009
e83f408
2d81982
4640a15
134ffff
97e25da
96bd56d
8fba9b2
a5b996a
990217e
1e7bac2
979df6b
e3dfcb4
56948c3
3e2ce66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ def VolcanoPlot( | |
gene='GENE', | ||
annotation=None, | ||
logp=True, | ||
title='Volcano Plot', | ||
xlabel=None, | ||
ylabel='-log10(p)', | ||
point_size=5, | ||
|
@@ -33,7 +32,8 @@ def VolcanoPlot( | |
genomewideline_color='grey', | ||
genomewideline_width=1, | ||
highlight=True, | ||
highlight_color="red" | ||
highlight_color="red", | ||
**kwargs | ||
): | ||
"""Return a Dash Bio VolcanoPlot figure. | ||
|
||
|
@@ -72,7 +72,6 @@ def VolcanoPlot( | |
plotting the raw value could be useful for other genome-wide plots | ||
(e.g., peak heights, Bayes factors, test statistics, and other | ||
"scores"). | ||
- title (string; default 'Volcano Plot'): Title of the graph. | ||
- xlabel (string; optional): Label of the x axis. | ||
- ylabel (string; default '-log10(p)'): Label of the y axis. | ||
- point_size (number; default 5): Size of the points of the Scatter | ||
|
@@ -110,11 +109,29 @@ def VolcanoPlot( | |
dataframe = pd.DataFrame( | ||
np.random.randint(0,100,size=(100, 2)), | ||
columns=['P', 'EFFECTSIZE']) | ||
fig = create_volcano(dataframe, title='XYZ Volcano plot') | ||
fig = create_volcano(dataframe, title=dict(text='XYZ Volcano plot')) | ||
|
||
plotly.offline.plot(fig, image='png') | ||
''' | ||
|
||
- Additional keys (misc.): Arbitrary arguments can be passed to modify the | ||
Layout and styling of the graph. A full reference of acceptable args is | ||
available [here](https://plotly.com/python-api-reference/generated/plotly.graph_objects | ||
.Layout.html). | ||
|
||
Some commonly used layout keys are: | ||
- title (dict: optional): Dict with compatible properties for the title of | ||
the figure layout. | ||
- xaxis (dict: optional): Dict with compatible properties for the x-axis of | ||
the figure layout. | ||
- yaxis (dict: optional): Dict with compatible properties for the y-axis of | ||
the figure layout. | ||
- height (number; optional): Sets the plot's height (in px). | ||
- width (number; optional): Sets the plot's width (in px). | ||
- margin (dict | plotly.graph_objects.layout.Margin instance): A dict or Margin | ||
instance that sets the separation between the main plotting space and | ||
the outside of the figure. | ||
- legend (dict | plotly.graph_objects.layout.Legend instance): A dict or Legend | ||
instance with compatible properties. | ||
""" | ||
|
||
vp = _VolcanoPlot( | ||
|
@@ -128,7 +145,6 @@ def VolcanoPlot( | |
) | ||
|
||
return vp.figure( | ||
title=title, | ||
xlabel=xlabel, | ||
ylabel=ylabel, | ||
point_size=point_size, | ||
|
@@ -140,7 +156,8 @@ def VolcanoPlot( | |
genomewideline_color=genomewideline_color, | ||
genomewideline_width=genomewideline_width, | ||
highlight=highlight, | ||
highlight_color=highlight_color | ||
highlight_color=highlight_color, | ||
**kwargs | ||
) | ||
|
||
|
||
|
@@ -274,7 +291,6 @@ def __init__( | |
|
||
def figure( | ||
self, | ||
title='Volcano Plot', | ||
xlabel=None, | ||
ylabel='-log10(p)', | ||
point_size=5, | ||
|
@@ -287,14 +303,13 @@ def figure( | |
genomewideline_width=1, | ||
highlight=True, | ||
highlight_color='red', | ||
**kwargs | ||
): | ||
"""Return a figure object compatible with plotly.graph_objects. | ||
|
||
Keyword arguments: | ||
- title (string; default 'Volcano Plot'): Title of the | ||
graph. | ||
- xlabel (string; optional): Label of the x axis. | ||
- ylabel (string; default '-log10(p)'): Label of the y axis. | ||
- xlabel (string; optional): Label of the x-axis. | ||
- ylabel (string; default '-log10(p)'): Label of the y-axis. | ||
- point_size (number; default 5): Size of the points of the scatter | ||
plot. | ||
- col (string; optional): Color of the points of the Scatter plot. Can | ||
|
@@ -322,6 +337,25 @@ def figure( | |
- highlight_color (string; default 'red'): Color of the data points | ||
highlighted because considered significant. Can be in any color | ||
format accepted by plotly.graph_objects. | ||
- Additional keys (misc.): Arbitrary arguments can be passed to modify the | ||
Layout and styling of the graph. A full reference of acceptable args is | ||
available [here](https://plotly.com/python-api-reference/generated/plotly.graph_objects | ||
.Layout.html). | ||
|
||
Some commonly used layout keys are: | ||
- title (dict: optional): Dict with compatible properties for the title of | ||
the figure layout. | ||
- xaxis (dict: optional): Dict with compatible properties for the x-axis of | ||
the figure layout. | ||
- yaxis (dict: optional): Dict with compatible properties for the y-axis of | ||
the figure layout. | ||
- height (number; optional): Sets the plot's height (in px). | ||
- width (number; optional): Sets the plot's width (in px). | ||
- margin (dict | plotly.graph_objects.layout.Margin instance): A dict or Margin | ||
instance that sets the separation between the main plotting space and | ||
the outside of the figure. | ||
- legend (dict | plotly.graph_objects.layout.Legend instance): A dict or Legend | ||
instance with compatible properties. | ||
""" | ||
|
||
if xlabel is None: | ||
|
@@ -355,13 +389,18 @@ def figure( | |
col = 'black' | ||
|
||
layout = go.Layout( | ||
title=title, | ||
title={'text': 'Volcano Plot', | ||
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. Should we be using the Alternatively we could drop So yeah, I guess my inclination is to drop 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. Dropped in 3e2ce66. |
||
'font': {'family': 'sans-serif', 'size': 20}, | ||
'x': 0.5, | ||
'xanchor': 'right', | ||
'yanchor': 'top' | ||
}, | ||
hovermode='closest', | ||
legend={ | ||
'x': 0.85, | ||
'y': 0.1, | ||
'bgcolor': '#f2f5fa' | ||
}, | ||
legend={'bgcolor': '#ebf1fa', | ||
'yanchor': 'top', | ||
'x': 1.01, | ||
"font": {"family": "sans-serif"} | ||
}, | ||
xaxis={ | ||
'title': xlabel, | ||
'zeroline': False, | ||
|
@@ -373,6 +412,8 @@ def figure( | |
} | ||
) | ||
|
||
layout.update(**kwargs) | ||
|
||
data_to_plot = [] # To contain the data traces | ||
tmp = pd.DataFrame() # Empty DataFrame to contain the highlighted data | ||
|
||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
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.
Since we're accepting
**kwargs
here and passing them togo.Layout
, do we actually need any of the other args you're adding here? We can list some of the common ones (including the ones you're including explicitly now) in the description here, they'd all work identically as part of kwargs.x_axis
andy_axis
: in the docstring there's no_
and I'd argue it's cleaner without, then these can just be left to kwargs as well.In order to keep the defaults you have but allow users to update the layout arbitrarily with kwargs after that, I suspect the easiest would be to generate the default layout first, then do
layout.update(**kwargs)
. A little exploring shows that this does a deep merge, so if your kwargs are justxaxis=dict(color="red")
you'll still get the rest of the x axis as set in the default layout.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.
I thought it might be nice to have the most commonly used args available explicitly, especially for users that use IDE's which show parameter info, but simply including them as part of the documentation is also an option. However, retaining them as explicit args would also potentially save users a trip to the Plotly graphing library docs (unless we also update dash-docs with some better examples). I think it's a trade-off between cleaner params (with everything as kwargs) and easier "default" use of the component.
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.
Fair point re: IDE docs & completion. That said for everything except
height
andwidth
you're still going to need to visit the graphing library docs to find out what goes inside the object, and it feels a bit arbitrary to be pulling in just a few layout options - as if the ones in kwargs are less-fully-supported or something. So I still think we'll be better off removing all of them and just documenting a few (the set you've proposed adding here looks good) in the docstring.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.
That's a great point - Updated in a5b996a.