-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Secondary y-axis subplot support #1564
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
Conversation
To try out this PR:
pip install https://12843-14579099-gh.circle-artifacts.com/0/dist/plotly-3.9.0%2B11.g6ec85ce5.tar.gz
Hi @jonmmease , I am getting an exception using this feature (I installed as per instruction above in my Conda environment running Python 3.7):
print(plotly.__version__) fig = tools.make_subplots( rows=2, cols=2, print_grid=False, specs=[ [{'secondary_y': True}, {'secondary_y': True}], [{'secondary_y': True}, {'secondary_y': True}] ] )
Outputs
3.9.0+11.g6ec85ce5
File "/Users/marco/PycharmProjects/plotting/metrics_evolution_over_time/grouped.py", line 169, in ply_plotter
[{'secondary_y': True}, {'secondary_y': True}]
File "/Users/marco/anaconda3/envs/my_env/lib/python3.7/site-packages/plotly/tools.py", line 585, in make_subplots
_check_keys_and_fill('specs', specs, SPEC_defaults)
File "/Users/marco/anaconda3/envs/my_env/lib/python3.7/site-packages/plotly/tools.py", line 570, in _check_keys_and_fill
_checks(arg_ii, defaults)
File "/Users/marco/anaconda3/envs/my_env/lib/python3.7/site-packages/plotly/tools.py", line 563, in _checks
"argument '{name}'".format(k=k, name=name))
Exception: Invalid key 'secondary_y' in keyword argument 'specs'
Looks like these lines in plotly.tools are missing a default for 'secondary_y':
# Default spec key-values SPEC_defaults = dict( is_3d=False, colspan=1, rowspan=1, l=0.0, r=0.0, b=0.0, t=0.0 # TODO add support for 'w' and 'h' ) _check_keys_and_fill('specs', specs, SPEC_defaults)
Changing the above with a default works around the error.
# Default spec key-values SPEC_defaults = dict( is_3d=False, colspan=1, rowspan=1, l=0.0, r=0.0, b=0.0, t=0.0, secondary_y=False # TODO add support for 'w' and 'h' ) _check_keys_and_fill('specs', specs, SPEC_defaults)
However, it seems that my secondary_y are all ignored, as fig.print_grid() outputs
This is the format of your plot grid:
[ (1,1) x1,y1 ] [ (1,2) x2,y2 ]
[ (2,1) x3,y3 ] [ (2,2) x4,y4 ]
Did I do something wrong in the installation process?
I also tried pip install git+git://github.com/plotly/plotly.py.git@enh_secondary_y and got the same problems.
Hi @marcotama, thanks for giving it a try.
Do you have the from _plotly_future_ import v4_subplots line above the plotly import? This is needed to "turn on" the new subplots functionality. The version 4 make_subplot function should be in plotly.subplots.make_subplots. If that's not the issue, could you double check that there isn't a second version of plotly.py installed (maybe through conda?)
Thanks!
Hi @jonmmease , I feel a little stupid! I was missing that import line.
It works perfectly! Thanks!
Is this going to be part of 3.9.0? Will it need the _plotly_future_ line?
Hi @marcotama, great! Thanks for giving it a try. The current stable version is 3.9.0 so this will go into 3.10.0.
And yes, prior to version 4.0 you'll need this _plotly_future_ line to use this functionality. In version 4 this will become the default behavior. So the secondary_y functionality should not be considered stable until version 4, but help with testing is definitely appreciated so please open bug reports for any trouble you run into while using the _plotly_future_ flags. Thanks!
Uh oh!
There was an error while loading. Please reload this page.
Overview
This PR introduces secondary
y-axissupport to thesubplots.make_subplotsand associated functions. This functionality is only available in thev4_subplotsfuture mode.make_subplots update
The
subplots.make_subplotsfunction not supports asecondary_ykey in the elements of thespecsargument. The figure methods for adding traces now also support asecondary_yargument.For example:
newplot-23
get_subplot
newplot-21
Update traces
newplot-22
Update yaxis
newplot-24
cc @nicolaskruchten @chriddyp