I am plotting river water levels, as obtained from the USGS.
I have the data in a list of dictionaries:
>>> time_series[0]
{‘value’: ‘113’, ‘qualifiers’: [‘P’], ‘dateTime’: ‘2025-08-10T08:15:00.000-05:00’}
>>> len(time_series)
1336
I am importing it into a Pandas dataframe and converting the dateTime column to an actual dateTime and value to numeric:
>>> df = pd.DataFrame(time_series)
>>> df["dateTime"] = pd.to_datetime(df["dateTime"])
>>> df["value"] = pd.to_numeric(df["value"], errors="coerce")
>>> df.dtypes
value int64
qualifiers object
dateTime datetime64[ns, UTC-05:00]
dtype: object
>>>
I’m then creating a figure and writing it to an image:
>>> fig = px.line(df, x="dateTime", y="value", title="foobar")
>>> fig.write_image('foo.png')
However, the image comes out with the x-axis in scientific notation:
I’ve gone through this a few times with ChatGPT and it doesn’t seem to have any useful suggestions. It seems as though my dataframe is properly formatted, but I’m no expert in Pandas. The actual dates seem within the 2 week range I asked for:
>>> df["dateTime"].min()
Timestamp('2025-08-10 08:15:00-0500', tz='UTC-05:00')
>>> df["dateTime"].max()
Timestamp('2025-08-24 06:00:00-0500', tz='UTC-05:00')
Any idea what I can do to get Plotly to understand the datetime format?
For the record, I’m on plotly 6.3.0:
>>> plotly.__version__
'6.3.0'
Thanks in advance!
EDIT
For what it’s worth, I walked through the time series exercise ( Time series and date axes in Python ) and when leaving the ‘data’ column as object, it worked right, however when converting it to a pandas datetime, it showed the same behavior of scientific notation.
My pandas version is 2.3.2
SECOND EDIT
Okay, so through the power of screwing around, I found that if I literally don’t convert the incoming datetime string into a pandas datetime object, then it actually formats properly.
The following image was produced using just the following:
>>> df = pd.DataFrame(time_series)
>>> df["value"] = pd.to_numeric(df["value"], errors="coerce")
>>> df.dtypes
value int64
qualifiers object
dateTime object
dtype: object
>>> px.line(df, x='dateTime', y='value', title='foo').write_image("foo.png")
I have no idea how any of this works now. But okay.