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?
#5
(Apr-04-2022, 04:33 PM)deanhystad Wrote: If you look at the documentation for matplotlib.ticker

https://matplotlib.org/stable/api/ticker_api.html

You see this
Quote:There are a number of locators specialized for date locations - see the dates module.
Follow the link:

Here's what I ended up with:

import pandas as pd
import matplotlib.pyplot as plt
 
sample_data = [3, 6, 2, 12, 15]
e = pd.date_range('2010-01-01', '2011-12-31',5) #these will be x-coordinates for data
f = pd.date_range('2009-06-30', '2014-12-31',10) #these will be x-axis labels
f = f.strftime('%Y-%m-%d') #reformatted axis labels
 
fig, ax = plt.subplots(1) 
ax.plot(e,sample_data)
ax.set_xticks(f, f, rotation=90) 
plt.show()
That seems to work.

Thanks all!
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, 07:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What data types can I use for default values? Mark17 1 599 Oct-09-2023, 02:07 PM
Last Post: buran
  Points not plotting with reference to x-tick labels Mark17 2 1,353 Jun-14-2022, 05:38 PM
Last Post: Mark17
  Floor division problem with plotting x-axis tick labels Mark17 5 2,244 Apr-03-2022, 01:48 PM
Last Post: Mark17
  How to read rainfall time series and insert missing data points MadsM 4 2,315 Jan-06-2022, 10:39 AM
Last Post: amdi40
  How to display combobox related values in labels Lalremruata 0 1,605 Jul-20-2021, 02:45 AM
Last Post: Lalremruata
  Fit np.polyfit to data points Laplace12 3 1,719 Jul-07-2021, 06:49 AM
Last Post: Gribouillis
  Only show every nth tick in chart tgottsc1 1 4,799 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,657 Nov-02-2020, 07:18 AM
Last Post: moose
  Complex X Tick Interval JoeDainton123 0 1,526 Oct-05-2020, 07:27 PM
Last Post: JoeDainton123
  Setting Tick Intervals In Sub Plots JoeDainton123 1 1,866 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