question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposed API for twin-axis support

See original GitHub issue

Twin 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:

  1. curve1 * curve2.opts(yaxis='twin'): curve1 has its yaxis on the left (default) and curve2 has its yaxis on the right
  2. curve1.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:

  1. The x-axis dimension must match otherwise trying to use twin-axes should be an error.
  2. 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 and Paths 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:open
  • Created a year ago
  • Reactions:5
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
douglas-raillard-armcommented, Jul 29, 2022

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:

class Meta(type):
    def __rlshift__(self, left):
        return self(left)

class Op(metaclass=Meta):
    def __init__(self, left):
        self.left = left

    def __rshift__(self, right):
        return self.op(self.left, right)


class Custom(Op):
    @staticmethod
    def op(left, right):
        return left * right

# We just created a new operator "<<Custom>>"
print(3 <<Custom>> 2)
3reactions
maximltcommented, Jul 18, 2022

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 image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to implement secondary y-axis? - hvPlot
See Proposed API for twin-axis support · Issue #5355 · holoviz/holoviews · GitHub. The workaround is to use a hook, and it depends...
Read more >
How to detect if a twin axis has been generated for a ...
I would like to propose a get_twin -> Axes function rather than has_twin -> bool , which has more applications. You can still...
Read more >
Multiple axes in Python - Plotly
Detailed examples of Multiple Axes including changing color, size, log axes, and more in Python.
Read more >
Epitaxies of Ca sulfates on calcite. II. The main {010}, {001 ...
S1 of the supporting information), and these features are more pronounced ... 5 (c) the 2D twin law changes too: [140] is the...
Read more >
matplotlib.axes.Axes.twinx — Matplotlib 3.6.2 documentation
Create a twin Axes sharing the xaxis. Create a new Axes with an invisible x-axis and an independent y-axis positioned opposite to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found