home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 1460894580

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/7593#issuecomment-1460894580 https://api.github.com/repos/pydata/xarray/issues/7593 1460894580 IC_kwDOAMm_X85XE3t0 127195910 2023-03-08T21:23:08Z 2023-05-06T03:24:36Z NONE

If you are encountering an error message that says "Plotting with time-zone-aware pd.Timestamp axis not possible", it means that you are trying to plot a Pandas DataFrame or Series that has a time-zone-aware pd.Timestamp axis using a plotting library that does not support time zones.

To fix this error, you can convert the time-zone-aware pd.Timestamp axis to a time-zone-naive datetime object. This can be done using the tz_localize() method to set the time zone, followed by the tz_convert() method to convert to a new time zone or remove the time zone information altogether.

Here is an example:

import pandas as pd import matplotlib.pyplot as plt

Create a time-series DataFrame with a time-zone-aware pd.Timestamp axis

data = pd.DataFrame({'value': [1, 2, 3, 4]}, index=pd.date_range('2022-03-01 00:00:00', periods=4, freq='H', tz='US/Eastern'))

Convert the time-zone-aware pd.Timestamp axis to a time-zone-naive datetime object

data.index = data.index.tz_localize(None)

Plot the DataFrame using Matplotlib

data.plot() plt.show()

In this example, we create a time-series DataFrame with a time-zone-aware pd.Timestamp axis using the pd.date_range() function with the tz parameter set to 'US/Eastern'. We then use the tz_localize() method to set the time zone to None to convert the axis to a time-zone-naive datetime object. Finally, we plot the DataFrame using Matplotlib and the plot() method.

Note that converting the time-zone-aware pd.Timestamp axis to a time-zone-naive datetime object means that the time zone information is lost, so make sure that this is acceptable for your use case before making this conversion.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  1613054013
Powered by Datasette · Queries took 81.579ms · About: xarray-datasette