0

I have the following code:

df = pd.read_csv('FilePath.csv',delim_whitespace= True,header=None)
df = df.loc[np.abs(df[2])<5]
x = df[0]
y = df[2]
c = df[5]
fig = plt.figure()
ax = plt.gca()
plt.xlabel('x')
plt.ylabel('z')
plt.axes().set_aspect('equal')
h,xedges,yedges,binnumber = scipy.stats.binned_statistic_2d(x, y, c, statistic='median', bins=300, range=None, expand_binnumbers=False)
XX, YY = np.meshgrid(xedges, yedges)

plot1 = ax.pcolormesh(XX,YY,h.T)
# Add a colorbar
cb = plt.colorbar(plot1,ax=ax,orientation = 'horizontal')
cb.set_label(r"Legend colorbar")

plt.show()

I am not able to place the colorbar at the top of the figure with the legend of the colorbar at the top of it. Any idea?

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • You may want to look at this answer: https://stackoverflow.com/a/13311914/9530017 – Liris Sep 11 '20 at 09:48
  • @Liris I read it, but there is a comment asking the same as I asking here and there was no answer. – topotamadre Sep 11 '20 at 10:19
  • In my linked answer, they explain how to position the colorbar in any place you want: just create axes in the place you want the colorbar ? – Liris Sep 11 '20 at 12:15

0 Answers0