I am working with a datetime indexed dataframe to visualize a temperature time series data.
Here is a snippet of the data set
Link to the hourly climate data: https://drive.google.com/file/d/1_2O0DpISmNfyt2_tEyopRxrzSKUd4n4u/view?usp=sharing
I'm plotting the index's timestamps in the x-axis. Here is the result for a linear x-axis:
Now, when I try to create a semilog plot using ax.set_xscale('log') (log scale for the x-axis and a linear scale for the y-axis), it does not work. The result is the exact same previous plot.
Here is what I've done so far:
import matplotlib.pyplot as plt
%matplotlib inline
import matplotlib.dates as mdates
import pandas as pd
data = pd.read_csv('data.txt', sep = "\t", decimal = b',')
# Convert the Time column to actual dates = datetime64[ns]
data['Time'] = pd.to_datetime(data['Time'], format='%d.%m.%Y-%H:%M:%S')
#Take the time as the index of the dataframe
data = data.set_index('Time')
#Downsampling the data
data_daily_mean = data.resample('D').mean()
data_weekly_mean = data.resample('W').mean()
data_monthly_mean = data.resample('M').mean()
# Plotting the temperature
fig, ax = plt.subplots(figsize=(12.8, 7.2))
ax.plot(data['Temperature'], marker='.', linestyle='None', label='Hourly Data')
ax.plot(data_daily_mean['Temperature'], marker=',', linestyle=':', label='Daily Mean')
ax.plot(data_weekly_mean['Temperature'], marker='*', linestyle='-', label='Weekly Mean')
ax.semilogx(data_monthly_mean['Temperature'], marker='o', linestyle='-', label='Monthly Mean')
ax.set_ylabel('Temperature [°C]')
ax.set_title('Outdoor Roofed Temperature')
ax.set_xscale('log') # How to make it work for dates?
ax.grid(True)
ax.legend()
# Set x-axis major ticks to monthly interval, on the months first day
ax.xaxis.set_major_locator(mdates.MonthLocator(bymonthday=1))
# Format x-tick labels as day number and 3-letter month name
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d %b'));
In case they don't appear, here is a link to the images:
https://drive.google.com/file/d/1YAxUK-azDrrzcRnIgQY3Ibcht0AY3JNc/view?usp=sharing
https://drive.google.com/file/d/1qJLE6MtNE6GSQkGUOGHDwpiV6sy8BDw7/view?usp=sharing
https://drive.google.com/file/d/1t-frQ6XtUIL3-mUdEnPD0FvIq6Ohx4Ih/view?usp=sharing