How to handle missing data with a scatter plot? #443
-
I have a scatter plot which should show the amount of heating time in each day on the x axis, and the corresponding amount of gas used on the y axis. I have something adapted from some other examples here, but it produces some spurious results. Because the gas data has only been available for a relatively short period of time in home assistant and the heating has been off over summer, what I was expecting to see was a line of dots down the x=0 line, but with some varying amount of gas used which corresponds to hot water and cooking. That is mostly what it looks like, but the problem is that there are points plotted indicating days with heating time but with gas quantities which are incorrect, and that means that all of the data is likely incorrect. I think this is because the length of the arrays for each entity are different as they are not paired up with each other, so when there is a day or more with data missing, the alignment is lost. YAML:
How do I go about forcing the data points to be matched with the same dates so that only those with all the data present are plotted? Edit - answer marked, but note minor correction to include x data:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hey there 👋 |
Beta Was this translation helpful? Give feedback.
-
Ok, I will give it a go thanks. |
Beta Was this translation helpful? Give feedback.
-
I think that solution would work, assuming that all three entities are available for the whole period of the graph. eg if the graph covers a year and there are days missing on one or more of the entities here and there, then resample would fill in those days and things would match up. The issue here is that one of the entities has only existed for a limited period of time, whereas the others have existed for longer. Setting the graph period so that it only covers the period where all three have existed does as far as I can tell produce sensible output. If I set it to cover a longer period, say a year, it plotly assumes that the entities all begin at the same time and so do not match properly. Checking the array values in the console confirms that. I could manually adjust the graph period so that it only covers the period where everything is already there, but I'd rather not have to keep going to back to change it all the time. I think a more robust method of matching dates explicitly is needed. I have been playing with chatgpt see if I can generate something useful but it's being stubbornly obtuse about it at the moment. It doesn't help that my knowledge of javascript is pretty limited. |
Beta Was this translation helpful? Give feedback.
I see. Try this instead of the resample.
I should add an "align" filter for these use cases