Python Forum
How to get evenly-spaced datetime tick labels regardless of x-values of data points?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get evenly-spaced datetime tick labels regardless of x-values of data points?
#3
(Apr-03-2022, 10:45 PM)Larz60+ Wrote: see: https://matplotlib.org/3.1.1/gallery/tic..._demo.html

How do you suggest I implement that?

I had previously worked successfully with this Class and np.linspace() as the first argument.

This does not work:

import matplotlib

a = ['2017-01-06', '2017-01-13', '2017-01-20', '2017-01-27', '2017-02-03', '2017-02-10', '2017-02-17', \
     '2017-02-24', '2017-03-03', '2017-03-10', '2017-03-17', '2017-03-24', '2017-03-31', '2017-04-07', \
     '2017-04-14', '2017-04-21', '2017-04-28', '2017-05-05', '2017-05-12', '2017-05-19']
b = [433, 1216, 1234, 2175, 2825, 3271, 3240, 2979, 2234, 3114, 3139, 2975, 3831, 3758, 4127, 4900, 4216,\
     4785, 4043, 4346]
fig, ax = plt.subplots(1) 

ax.plot(a,b)
ax.xaxis.set_major_locator(matplotlib.ticker.FixedLocator(list(pd.date_range('2010-01-01', '2011-12-31',5))))
plt.xticks(rotation=90) 
plt.show()
With or without that list() constructor, I get TypeError: type Timestamp doesn't define __round__ method
Reply


Messages In This Thread
RE: How to get evenly-spaced datetime tick labels regardless of x-values of data points? - by Mark17 - Apr-04-2022, 01:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What data types can I use for default values? Mark17 1 594 Oct-09-2023, 02:07 PM
Last Post: buran
  Points not plotting with reference to x-tick labels Mark17 2 1,348 Jun-14-2022, 05:38 PM
Last Post: Mark17
  Floor division problem with plotting x-axis tick labels Mark17 5 2,231 Apr-03-2022, 01:48 PM
Last Post: Mark17
  How to read rainfall time series and insert missing data points MadsM 4 2,309 Jan-06-2022, 10:39 AM
Last Post: amdi40
  How to display combobox related values in labels Lalremruata 0 1,601 Jul-20-2021, 02:45 AM
Last Post: Lalremruata
  Fit np.polyfit to data points Laplace12 3 1,715 Jul-07-2021, 06:49 AM
Last Post: Gribouillis
  Only show every nth tick in chart tgottsc1 1 4,788 Feb-01-2021, 04:30 PM
Last Post: j.crater
  How can I scroll over my data points when creating plots in Python? (I'm using Spyder moose 0 1,654 Nov-02-2020, 07:18 AM
Last Post: moose
  Complex X Tick Interval JoeDainton123 0 1,525 Oct-05-2020, 07:27 PM
Last Post: JoeDainton123
  Setting Tick Intervals In Sub Plots JoeDainton123 1 1,862 Oct-03-2020, 11:52 PM
Last Post: scidam

Forum Jump:

User Panel Messages

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