plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.11k stars 2.54k forks source link

Faulty shapes when axis type set to 'category' #759

Closed ghost closed 7 years ago

ghost commented 7 years ago

Shapes seem buggy when displayed on a time series plot with axis type set to 'category' while it is working as expected when set to 'auto' (date index).

If you zoom on the shape, you will clearly see that it is not what you intended to plot: it draws a rectangle instead of a vertical line in the case below. I have encountered that problem with different index format (datetime, integer, string) displayed as 'category'

import pandas as pd
import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode
from datetime import datetime

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")

data = [
    go.Scatter(
          x=df.Date,
          y=df['AAPL.Close']
    )
]

layout = go.Layout(
    xaxis=dict(
        type='category', # change this option to _auto_ for a correct shape
    ),
    shapes=[
        dict(
            x0=datetime(2015, 11, 5),
            y0=min(df['AAPL.Close']),
            x1=datetime(2015, 11, 5), # x1 = x0 for a vertical line
            y1=max(df['AAPL.Close'])
        )
    ]
)
fig = go.Figure(data=data, layout=layout)
iplot(fig)

Ouput: screenshot from 2017-05-23 11-54-51

Zoom on the vertical line: screenshot from 2017-05-23 11-51-03

cldougl commented 7 years ago

Hi there, Thanks for reporting this issue! It's actually in our underlying javascript library so I've opened an issue in that repo. I will close this issue in favour of: https://github.com/plotly/plotly.js/issues/1720, once that's resolved, you will no longer see the problem with our python api.

sb0007 commented 5 years ago

is this yet to be fixed?