Skip to content
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

Negative values misssing for x-axis in histogramm2dcontour #261

Open
thecem opened this issue Mar 5, 2023 · 2 comments
Open

Negative values misssing for x-axis in histogramm2dcontour #261

thecem opened this issue Mar 5, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@thecem
Copy link
Contributor

thecem commented Mar 5, 2023

Describe the bug
Beside there are negative values, the negative temperature values are not shown in histogramm2dcontour.

Screenshots
grafik

yaml

type: custom:plotly-graph
entities:
  - entity: sensor.at_yesterday
    statistic: mean
    period: day
    time_offset: '-1d'
    internal: true
    filters:
      - filter: i>0
    fn: $fn ({ ys, vars }) => vars.temperature = ys
  - entity: sensor.gas_verbrauch_kwh
    statistic: state
    period: day
    name: Gas
    internal: true
    filters:
      - filter: i>0
      - derivate: d
    fn: $fn ({ ys, vars }) => vars.gas = ys
  - entity: ''
    x: $fn ({ vars }) => vars.temperature
    'y': $fn ({ vars }) => vars.gas
    mode: markers
    name: points
    marker:
      color: rgb(102,0,0)
      size: 3
      opacity: 0.4
    type: scatter
  - entity: ''
    line:
      shape: linear
      color: blue
    filters:
      - fn: |
          ({ys, xs, vars}) => {
            return {xs: vars.temperature, ys: vars.gas};
          }
      - trendline
  - entity: ''
    filters:
      - fn: |
          ({vars}) => {
            const xs = vars.temperature;
            const ys = vars.gas;
            const pairs = xs.map((x, i) => [x,ys[i]])
              .filter( ([x,y]) => Number.isFinite(x) && Number.isFinite(y)) // unavailables in the x axis break trendlines
              .sort((a,b)=>a[0]-b[0]); // the trendline filter expects the x axis to be sorted
            const r = {
              xs: pairs.map(([x,y])=>x),
              ys: pairs.map(([x,y])=>y),
            };
            console.log(r);
            return r;
          }
      - trendline
      - store_var: trend
    x: >-
      $fn ({ vars }) => vars.trend.xs.map(x=>+x) // the trendline made dates out
      of the x axis
    'y': >-
      $fn ({ vars }) => vars.trend.ys // and since this is a raw_plotly_config,
      we need to set x and y ourselves
  - entity: ''
    x: $fn ({ vars }) => vars.temperature
    'y': $fn ({ vars }) => vars.gas
    name: density
    ncontours: 40
    colorscale: YlGnBu
    nbinsx: 15
    nbinsy: 15
    reversescale: true
    showscale: false
    line:
      color: lightgray
    type: histogram2dcontour
  - entity: ''
    x: $fn ({ vars }) => vars.temperature
    name: x density
    texttemplate: '%{x:0.1f}'
    marker:
      color: "rgb(40\t57\t143\t)"
    yaxis: y2
    opacity: 1
    type: histogram
  - entity: ''
    x: undefined
    'y': $fn ({ vars }) => vars.gas
    name: y density
    texttemplate: '%{y:0.1f}'
    marker:
      color: "rgb(40\t57\t143\t)"
    xaxis: x2
    type: histogram
hours_to_show: 4800
title: >-
  $fn({getFromConfig})=>`Heating - Last ${getFromConfig('hours_to_show')/24}
  days`
raw_plotly_config: true
layout:
  margin:
    t: 20
    l: 70
    r: 20
    b: 70
  height: 400
  bargap: 0.1
  showlegend: false
  xaxis:
    title:
      text: Outside Temperature (°C)
    autorange: true
    domain:
      - 0
      - 0.85
    showgrid: false
    zeroline: false
  yaxis:
    title:
      text: Gas burned (kWh per day)
    domain:
      - 0
      - 0.85
    showgrid: false
    zeroline: false
  xaxis2:
    domain:
      - 0.85
      - 1
    showgrid: false
    zeroline: false
  yaxis2:
    domain:
      - 0.85
      - 1
    showgrid: false
    zeroline: false

Additional context
With following config, we see the negative values for temperature. On another mashine this is working, asi posted here #216.
May there is something wrong with my config above.

THX 4 help!

grafik

type: custom:plotly-graph
entities:
  - entity: sensor.at_yesterday
    statistic: mean
    period: day
    time_offset: '-1d'
    show_value: true
    name: Ø Temp
  - entity: sensor.hmip_bw19_temperature_humidity_sensor_outdoor_temperature
    statistic: mean
    period: hour
    show_value: true
    name: Out Temp
  - entity: sensor.gas_verbrauch_kwh
    statistic: state
    period: day
    type: bar
    opacity: 0.5
    texttemplate: '%{y:0.1f}'
    filters:
      - derivate: d
    name: Gas
hours_to_show: 360
refresh_interval: 10
title: Heat Energy (Gas/Temp)
@thecem thecem added the bug Something isn't working label Mar 5, 2023
@thecem
Copy link
Contributor Author

thecem commented Mar 5, 2023

chnage "hours_to_show: 4800" to "hours_to_show: 2112":

grafik

@dbuezas
Copy link
Owner

dbuezas commented Mar 5, 2023

If you go too far into the past it can happen that one of the entities has more data points than the other one.
I suggest:

  • Plot all entities in a scatter plot to inspect if all go equally far away into the past
  • add resample filters to force them all to have the same amount of datapoints, and to become aligned
  • Remove the filter: i>0
  • use hours_to_show: 6M instead of 4800 to make it easier to read.

Let me know if you find something out!, I don't think this is a bug in the card

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants