Proposed API for twin-axis support
See original GitHub issueTwin axes is an often requested feature (e.g. see #396, #1594, #3011) and HoloViews should support this type of plot without having to resort to ugly custom hooks.
In this issue I would like to propose an API for discussion. In particular, I think the most intuitive approach would be to support twin-axes by creating a simple overlay, where one of the components has yaxis='twin'
specified as a plot option. Right now, the possible values for yaxis
(for bokeh) are ['left', 'right', None, True, False]
which means 'twin'
would be added to this list. For matplotlib, the options are ['left', 'right', None]
(I don’t see why true and False shouldn’t also be supported here though!)
As 'left'
and 'right'
are already supported, using 'twin'
would add axes on the opposite side for the component it is attached to. For instance:
curve1 * curve2.opts(yaxis='twin')
: curve1 has its yaxis on the left (default) and curve2 has its yaxis on the rightcurve1.opts(yaxis='right') * curve2.opts(yaxis='twin')
: curve1 has its yaxis on the right and curve2 has its yaxis on the left
I think this would be intuitive enough given how everything currently works. In principle, this should support overlaying two NdOverlays
so that you have two legends, one for each side.
Suggested rules:
- The x-axis dimension must match otherwise trying to use twin-axes should be an error.
- Twin axes make sense for a number of chart elements (e.g. curves, scatter) but I don’t think they really make sense for
Points
andPaths
which exist in a homogenous 2D space (where you can sensibly imagine rotations). I don’t think this option will make sense for all element types (e.g. can this really be sensible for bar charts?)
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:11 (8 by maintainers)
Top GitHub Comments
It’s maybe a terrible idea but it just struck me that we actually can have an unlimited supply of infix operators in Python if we are ready to make pylint scream about the missing whitespaces:
Allowing twin axes makes sense too for two elements that are not of the same type. E.g. in this example taken from Microsoft’s site: https://support.microsoft.com/en-us/office/add-or-remove-a-secondary-axis-in-a-chart-in-excel-91da1e2f-5db1-41e9-8908-e1a2e14dd5a9#OfficeVersion=macOS