Even I have experiences with other program languages - with Python I am a bloody beginner I must say. Nevertheless I would like to use matplotlib.dates to plot the course of measured temperature data over the date, dd.mm.yy (x-axis). The problem for me: the measurement of the temperatures is not regularly, it could be every day, every second day, every fifth and so on. So I have values which are measured not equidistant in time, but I still want them plotted over a linear date-axis (x-axis), eventually linked with a continuous line.
I worked with several example, modules and date formatters but I couldn’t succeed. Always, I found, it is necessary to have for every equidistant date-point a value, for 100 days 100 values. I have within 100 days 30 value-date couples, not equidistant…
I would be very glad to get some hints or examples I can work with.
Thank you very much for any remark!
Can you post an example of what you tried? It is very difficult to help you starting ab initio.
It is not clear if you want the spacing on the screen to always be even (
ax.plot(range(len(data)), data)) or spaced to represent how far apart in time they are (
Thank you very much for your response!
I experimented (within IDLE) with two examples of matplotlib’s classes “dataFormatters”, the default and the “conciseDataFormatter” (Formatting date ticks using ConciseDateFormatter — Matplotlib 3.5.1 documentation ). Still I think I’d like to start with one of these two programs. Both have the scalable date-x-axis I want, but unfortunately both also have the solid coupling of one (random) value to every timeDelta, which I can’t break up. Concerning my task: let’s say over one year I will have 50 values measured in very different time distances. E.g. 10 values in March, 3 values in August, …
Since I am still learning Python, I didn’t manage to change the examples to distribute less values, assigned to specific days, casually over the continuous date-axis.
Hope it is a bit clearer what I want to do. At first this task seemed trivial to me, but neither Excel nor Numbers can do it without any tricks. So I would be very happy to make it with Python.
Can you please share a code snippet of what you have tried? It is impossible to help you any further based on information we have .
Sorry, here is it
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
base = datetime.datetime(2021, 11, 5)
dates = [base + datetime.timedelta(days=i) for i in range(365)]
N = len(dates)
y = np.cumsum(np.random.randn(N)) # X*
fig, axs = plt.subplots(2, 1, constrained_layout=True, figsize=(6, 6))
lims = [(np.datetime64('2021-11'), np.datetime64('2022-11')),
for nn, ax in enumerate(axs):
for label in ax.get_xticklabels():
axs.set_title('Default Date Formatter')
X* instead of these continuos random values I'd like to insert
8 discret value at certain days (later more):