I am trying to use this code:
import matplotlib.pyplot as plt
import numpy as np
x = np.array([0,1,2,3])
y = np.array([20,21,22,23])
my_xticks = ['John','Arnold','Mavis','Matt']
plt.xticks(x, my_xticks)
plt.plot(x, y)
plt.show()
(source: plot with custom text for x axis points)
in time-series .csv where I have 2 columns. The one column has timestamps and the other column has temperatures. I need in the plot, and more specifically in the x-axis instead of timestampts' values to have something like this: "day1", "day2", "day3",... Any ideas? I am trying to approach it but all my efforts are very dissapointing, since I haven't managed to realized it.
>>>> UPDATE (23/4/2023): <<<<
This is the code I use:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.read_csv("measurements.csv", sep=",")
use_days = [1, 2, 3, 4, 5, 6, 7] # <-- put here the days numbers to show
xticks_labels = [f"day{i+1}" for i, _ in enumerate(df["Date"])]
selected_labels = [xticks_labels[idx] for idx in [i-1 for i in use_days]]
plt.xticks(df["Date"].iloc[[i-1 for i in use_days]], selected_labels, rotation=45, fontsize=12) #adjust those values if needed
plt.show();
And I get this error:
ConversionError: Failed to convert value(s) to axis units: