Python Forum
How does pd.date_range() fit in with axs[].set_xticks() ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does pd.date_range() fit in with axs[].set_xticks() ?
#2
set_xticks is expecting a list of str
Quote:matplotlib.axes.Axes.set_xticks
Axes.set_xticks(ticks, labels=None, *, minor=False, **kwargs)[source]
Set the xaxis' tick locations and optionally labels.

If necessary, the view limits of the Axis are expanded so that all given ticks are visible.

Parameters
tickslist of floats
List of tick locations.

labelslist of str, optional
List of tick labels. If not set, the labels show the data value.

minorbool, default: False
If False, set the major ticks; if True, the minor ticks.

**kwargs
Text properties for the labels. These take effect only if you pass labels. In other cases, please use tick_params.
Pandas date_range returns a Datetimeindex. A Datetimeindex is an immutable ndarray-like of datetime64 data
Quote:pandas.DatetimeIndex
class pandas.DatetimeIndex(data=None, freq=NoDefault.no_default, tz=None, normalize=False, closed=None, ambiguous='raise', dayfirst=False, yearfirst=False, dtype=None, copy=False, name=None)[source]
Immutable ndarray-like of datetime64 data.

Represented internally as int64, and which can be boxed to Timestamp objects that are subclasses of datetime and carry metadata.
So when you call pandas.daterange() you are getting back an array of things that look like 64 bit integers, not strings. Do you want a bunch of really big integers appearing as tick labels?
Mark17 likes this post
Reply


Messages In This Thread
RE: How does pd.date_range() fit in with axs[].set_xticks() ? - by deanhystad - Jun-09-2022, 02:58 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020