Plotly interactive Graph Card

I mean the traces, the grid looks great!

If youā€™re referring to ā€œGrow Light Stateā€ traces, intended as well.

:ok_hand: cool, my design eye is as good as my french so donā€™t let my suggestion bother you, the plots look very nice

:grin: Really appreciated. Thanks

Hello again,

Is there a way for opposite y axes with different range values to always share the same lines, even when zoomed?

Thanks.

I think this is achieved with scaleanchor and scaleratio but havenā€™t tried it myself
See here: Layout.yaxis in JavaScript

And let me know how it goes, Iā€™m curious

:+1: Will doā€¦

So far Iā€™ve managed to find a way to align the two yaxes by setting the yaxes defaults: rangemode: tozero and tyckmode: sync.
eg1

This seems to work to some extent at least. Once I zoom, scroll or pan they are out of sync.
eg2

Setting the autorange_after_scroll to true seems to be partialy doing the job to keep them in sync, because it only applies to the main yaxis entities. Additional yaxes seem to be ignored by this function.

type: custom:plotly-graph
entities:
  - entity: sensor.gc131_aw_tree_pollen_0d
    name: E1 (yaxis)
  - entity: sensor.gc131_aw_ragweed_pollen_0d
    name: E2 (yaxis)
  - entity: sensor.gc131_aw_grass_pollen_0d
    name: E3 (yaxis)
  - entity: sensor.gc131_aw_mold_pollen_0d
    name: E4 (yaxis2)
    yaxis: y2
hours_to_show: 24
refresh_interval: 10
autorange_after_scroll: true
layout:
  yaxis2:
    tickfont:
      color: red
defaults:
  entity:
    fill: tozeroy
  yaxes:
    rangemode: tozero
    tickmode: sync

I found a way!

As you see, the ticks of y2 are forced to match those of y (even if they land on numbers like -0.069). And they stay in synch while zooming/scrolling
Kapture 2023-12-06 at 00.12.00

The trick is this:

layout:
  yaxis2:
    overlaying: y
    zeroline: false
    tickmode: sync

I based it from this example in the Plotly PR that adds tickmode: sync.

It does indeed, but only as long as autorange_after_scroll is set to false. If you set that to true, which you should if you want the plot to be rescaled so it could fit the graph when zoomed, the sync is gone, because as far I can see autorange_after_scroll only affects the main yaxis traces and ignores additional yaxes, causing the traces bound to the main yaxis to scale to fit, while secondary yaxes are ignored.

Iā€™m trying to visualize when different types of lights turn on/off during the day. My idea was having a yellow and red line at the bottom at two different levels on the yaxis, representing the two lights when turned on. The question is, how can I have one of lines filled from 4 to 2 on the yaxis and not all the way to the bottom (0)? Here is my code:

      - entity: input_boolean.evening_lights
        showlegend: false
        name: KvƤllslampor
        line:
          width: 0
        fill: tozeroy
        fillcolor: rgba(220, 230, 20, 1)
        filters:
          - map_y: 'y === "on" ? 2 : 0'
          - resample: 1m
      - entity: switch.shelly_altanen
        showlegend: false
        name: Julbelysning
        line:
          width: 0
        fill: tonexty
        fillcolor: rgba(220, 30, 30, 1)
        filters:
          - map_y: 'y === "on" ? 4 : 2'
          - resample: 1m

image

Try removing the fill, setting a width, and mapping to null instead of zero when the light is off

1 Like

Wow thank you for quick reply. Removing fill and use line width worked like a charm! :slight_smile:

You can also use a third yaxis (yaxis3) and set the domain and range of that specific yaxis. This means the position of zero is not anymore dependant on your other entities

Iā€™ll look into it. Iā€™m not sure how this works, nor how to set it up.

But as far as Iā€™ve seen, after zoom or pan, pressing the autoscale button seems to be doing the trick, by scaling the secondary yaxis accordingly, thus making the whole thing sort of feasible while allowing to keep the autorange set to true. The major inconvenience of that is that itā€™s a manually triggered event. It wouldā€™ve been much better if the autoscale couldā€™ve been triggered automatically after each zoom or pan. Iā€™ve done some research and saw that someone tried to implement that function in plotly python and actually succeeded, but I donā€™t donā€™t know how that could be adopted to HA.

autorange_after_scroll is what you want. Itā€™s not perfect but it does what you want.

If you were to set up a third axis, you can also fix its range so it wonā€™t change while you zooom the plot. Just google plotlyjs multiple yaxes and plotlyjs fix yaxis range.

Hi,
First, thanks a lot for this great card. Itā€™s wonderful.
Second, I have issues when trying to edit. The edition window moves a lot under Safari. Do you know if it is possible to fix that (except changing the browser :wink:)?
Thanks.

Thank! happy to hear you like it :slight_smile:
Try setting refresh_interval to 0, removing it or setting it to auto. Updates while editing reset the whole plot.

If that is not the problem, then please change the browser open a bug ticket in the repo and Iā€™ll take a look before the next release

1 Like

Unfortunately, that does not seem to work.
Here is a video to see how it behaves. Iā€™ll open a ticket, sure.
plotly

I just recognized, that my graph shows only cca. 1,5 week data. Why? Does the Plotly has some restriction?
As you can see the ā€œoldestā€ data is from 28th of November (yesterday it was showing from 27th of November), but I set up this sensor at 11th of November.