I am getting lost in different methods used in matplotlib.
I want to create a colour-coded scatter plot with a colorbar on the side and datetime on the x axis.
But depending on how I define my ax, I get different errors.
Below is the core of my code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.cm as cm
import matplotlib.dates as mdates
#.....loading files etc.
norm = mcolors.Normalize(vmin=0,vmax=1000)
timerange = pd.date_range(start='2015-01-01', end='2016-01-01', freq='30D')
### PLOTTING
fig = plt.figure(figsize=(6.,5))
ax = fig.add_subplot(111)
for Af in Afiles:
for index, row in Af.iterrows():
time = pd.to_datetime(row['date'], format="%Y-%m-%d")
plt.scatter(time, row['A'], c=row['z'], norm=norm, cmap=colormap,edgecolor='k', lw=0.8, s=80)
plt.xticks(timerange, rotation=90)
ax.xaxis.set_major_formatter(mdates.DateFormatter("%d/%m/%Y"))
plt.xlabel('Time', fontsize=11, color='k')
clb = fig.colorbar(ax)
clb.ax.set_title('Value', y=-0.125, fontsize=11)
clb.ax.invert_yaxis()
fig.tight_layout()
this produces AttributeError: 'AxesSubplot' object has no attribute 'autoscale_None'
but if I specify my ax as the scatter plot so that I can get my colour-coding working, I then have trouble with the axis formatter.
Writing instead ax = plt.scatter generates AttributeError: 'PathCollection' object has no attribute 'xaxis'.
How can I have both the colorbar AND formatted axis ticks?
