Skip to content

Problem plotting historical time series #1402

Closed
@elysiumfield

Description

@elysiumfield

I have recently updated plotly to ver 3.5.0 and am having problems plotting historical time series. The test code is as follows:

import numpy as np
import pandas as pd
import plotly.graph_objs as go
import plotly.offline as pyo
dt = pd.date_range(start='1969-12-31', periods=270, freq='Q')
t1 = []
t1.append(dict(x=dt, y=np.ones(270), name='cape', type='scatter'))
layout = go.Layout(title="test", width=1800, height=930, font=dict(size=27), titlefont=dict(size=42))
fig = go.Figure(data=t1, layout=layout)
pyo.plot(fig, filename='test.html', auto_open=False, show_link=False)

This code returns the error:

  File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\offline\offline.py", line 645, in plot
    '100%', '100%', global_requirejs=False)

  File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\offline\offline.py", line 336, in _plot_html
    jdata = _json.dumps(figure.get('data', []), cls=utils.PlotlyJSONEncoder)

  File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 238, in dumps
    **kw).encode(obj)

  File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\utils.py", line 168, in encode
    encoded_o = super(PlotlyJSONEncoder, self).encode(o)

  File "C:\ProgramData\Anaconda3\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)

  File "C:\ProgramData\Anaconda3\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)

  File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\utils.py", line 233, in default
    return encoding_method(obj)

  File "C:\ProgramData\Anaconda3\lib\site-packages\plotly\utils.py", line 297, in encode_as_datetime
    obj = obj.astimezone(pytz.utc)

OSError: [Errno 22] Invalid argument

However, defining dt = pd.date_range(start='1970-03-31', periods=270, freq='Q'), everything works fine. I am positive that previous versions of plotly could plot datetimeindex that was older.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions