plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
17.06k stars 1.87k forks source link

Surface graph has issue with small time ranges #3306

Open ShaneHudson opened 5 years ago

ShaneHudson commented 5 years ago

Hello,

I've had an issue for quite a while and thought it would be good to raise here. It's an issue with graphs that are over a small amount of time. I've attempted to make a demonstration but the screenshot below will show my issue more clearly.

Take a look at the following: A) https://jsfiddle.net/Lv4qpoyu/3/ B) https://jsfiddle.net/5au0xepd/1/

In A) you can see some random data over 50 minutes. In B) you can see random data over 50 seconds. A) works perfectly well, nice little graph. B) looks like an utter mess and is near impossible to use.

So that brings us to C), the screenshots (the first taken a few months ago, the second today) below that shows my real dataset. In a 2D heatmap it works fine but in a 3D surface graph it shows the data correctly but with the axis completely messed up. Sometimes it looks worse than others, but all the time there is a continuation of the date (y) axis. Sometimes it requires you to zoom out to see, but it is always there in the distance. This makes it unusable to me if I want to put it in front of users.

44929865-5e8da780-ad54-11e8-8795-0c2353f09984

screenshot 2018-12-04 11 03 52

When I've looked online for help I found someone else having the exact same issue but they were using the python version of the library with a scatter3d.

This seems to be a bug opposed to an issue in my code. I have autorange set to false, the range of data is correct (["2018-09-06 20:48:32", "2018-09-06 20:55:57"] for second screenshot) and is using moment dates. I have double checked it on the latest version too and no change. Does anyone have any idea what is causing this issue?

Cheers Shane

ShaneHudson commented 5 years ago

It looks like this may be related to https://github.com/plotly/plotly.js/issues/3155 but would appreciate any help on the matter.

archmoj commented 5 years ago

@ShaneHudson Thank you very much for reporting this issue.

ShaneHudson commented 5 years ago

Also another thing I've noticed, potentially related to this, is if there is no data on the graph but ranges are set on the axis then for the heatmap it shows correct ranges but the surface plot shows from 2000 to 2001.

archmoj commented 5 years ago

@ShaneHudson Could you please create a demo related to the second issue?

ShaneHudson commented 5 years ago

Thanks for doing that bug fix @archmoj. Do you have any idea when the next version will be published on npm please?

archmoj commented 5 years ago

My pleasure @ShaneHudson. And thank you for using Plotly at first place! Version 1.43.0 is setup and it would possibly be released tomorrow. There are other bug fixes and improvements related to axis ticks & surface traces. In particular this PR should help improve the accuracy of data points on the surface. Although concerning small time-steps we are still working on the dataScale issue as well as local time offsets on 3D axes and webGL. Therefore this issue is still open. But until it fixed, one practical solution may be to use minutes instead of the whole date in the axis ticks and then add the date info into the axis label using a break line. Now with this PR being merged, your graph could look like this demo.

archmoj commented 5 years ago

@ShaneHudson Also here is an alternative demo using superscripts & break-lines. Hope it may help.

archmoj commented 5 years ago

@ShaneHudson FYI - here is the new release v.1.43.0.

etpinard commented 5 years ago

@archmoj can we close this issue?

archmoj commented 5 years ago

@etpinard No. It is not fixed yet.

ShaneHudson commented 5 years ago
screenshot 2018-12-20 20 55 01

I've upgraded to the latest version of Plotly, so here's an updated graph. Looking across a minute.

archmoj commented 5 years ago

@ShaneHudson Curious to know if you noticed any improvement?

ShaneHudson commented 5 years ago

I'm afraid not. I understand that the very small time scales are bound to throw it off, but the use-case is a raspberry pi that is uploading scans of radio frequency at regular intervals. The steps on the graph are caused by the scan being done in sweeps.

Another thing I noticed but probably related to this is that the 3D graph also struggles/fails when only one point in time is available. Is that expected behaviour?

ShaneHudson commented 5 years ago

screenshot 2018-12-21 11 30 05

Here's another screenshot.

ShaneHudson commented 5 years ago

Do note though that the bug does look different that it did originally, but my data has changed since then so I am looking at a small time range.

wuyuanyi135 commented 4 years ago

+1. https://codepen.io/wuyuanyi135/pen/bGNrvym When the date difference is within one day, the display was problematic.

jfftonsic commented 4 years ago

The bug still happens, here is a simple plotly.py that reproduces this kind of error

import plotly.graph_objects as go
from datetime import datetime

s = go.Surface()
# s.x = ["2020-05-29T09:00:00","2020-05-29T10:00:00","2020-05-29T11:00:00"]
# s.x = ["2020-05-29","2020-05-30","2020-05-31"]
s.x = [datetime(2020, 5, 29, 9, 0, 0), datetime(2020, 5, 29, 10, 0, 0), datetime(2020, 5, 29, 11, 0, 0)]
s.y = [1, 1.5, 3]
s.z = [[0.5, 2, 2.5], [0.5, 2, 2.5], [0.5, 2, 2.5], [0.5, 2, 2.5], [0.5, 2, 2.5], [0.5, 2, 2.5], [0.5, 2, 2.5],
       [0.5, 2, 2.5], [0.5, 2, 2.5], ]
s.scene = 'scene1'

layout = go.Layout()
# the below assignment is just for the IDE auto-completion to work..
scene1 = go.layout.Scene(layout.scene1)
# scene1.xaxis.tickmode = 'array'
# scene1.xaxis.type = 'category'

layout.scene1 = scene1

fig = go.Figure(s, layout=layout)
fig.show()

which results in image

I managed to find a workaround which is uncommenting the lines

# scene1.xaxis.tickmode = 'array'
# scene1.xaxis.type = 'category'

It will not fit every use case but... it's what I got right now after hours banging head on the wall.

jackparmer commented 4 years ago

This issue has been tagged with NEEDS SPON$OR

A community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort.

What Sponsorship includes:

Please include the link to this issue when contacting us to discuss.

hborchardt commented 3 years ago

Hi, I would like to know if you are able to and would be interested in trying to move forward the related pull request that I opened in the gl-axes3d repository that you depend on? My main motivation in the PR is improving plotly :) and I saw that plotly maintainers are also maintaining some of the gl-vis repositories. @archmoj maybe?

Quost commented 3 years ago

Take a look at the following: A) https://jsfiddle.net/Lv4qpoyu/3/

Hey, how are you doing? I found this issue, and there is something related to what I'm facing here. You shared above a fiddle, and there is an axis label that is quite big, and this label enters the chart as you can see here:

image

I have some dates and would like to use them on my x labels, but it's not getting nice: image

positron96 commented 8 months ago

Any progress on this? I see there is a related PR for a project that haven't been updated in 4 years...

hborchardt commented 8 months ago

Hi @positron96 , I still like my changes in that PR. Currently the pipeline for my project that uses plotly patches the plotly bundle with those adjustments, which is not ideal 😄 but works. I can post the script later, in case nothing will happen.

hborchardt commented 8 months ago

Here's the patch as a bash script, to be called with the dist folder containing plotly as first argument:

set -x
PATH_WHERE_TO_REPLACE=$1;

# replace `* model * vec4(something)` with `* (model * vec4(something))` for better numerical stability in 3D graphs
find $PATH_WHERE_TO_REPLACE -type f -name "*plotly*.js" | xargs sed -r -i -e 's/\* model \* vec4\(([^\)]*)\)/* (model * vec4(\1))/g'