0
# Plotting Forward Modelling
fig1, ax = plt.subplots(2, figsize=(10, 10))
ax[0].set_title('model')
ax[0].plot(x, g, '.')
ax[0].set_xlim([min(x), max(x)])
ax[0].set_ylabel('gravity anomaly (mgal)')
coll = PolyCollection(kotak, array=drho, cmap='jet', edgecolors='none', linewidth=0.0)
ax[1].add_collection(coll)
ax[1].autoscale_view()
# coll.set_clim()  # set batasan colorbar
ax[1].set_xlim(min(x), max(x))
ax[1].set_ylim(0, 1)
ax[1].invert_yaxis()
plt.plot(centroide[:, 0], centroide[:, 1], 'k.')
d = plt.colorbar(coll, ax=ax[1])
ax[1].set_ylabel('Depth (m)')
ax[1].set_xlabel('Distance (m)')
d.set_label('\u0394 \u03C1 (kg/m^3)')
plt.tight_layout()
plt.show()

and the result is: enter image description here

My question is, how do I make image 1 above image 2 aligned and the colorbar is to the right of image 2? Thank You

  • [matplotlib colorbar in each subplot](https://stackoverflow.com/questions/23876588/matplotlib-colorbar-in-each-subplot) Here's a great answer. You may find it helpful. However, there are no examples of graphs stacked vertically. – r-beginners Apr 08 '20 at 14:05
  • [Here](https://stackoverflow.com/questions/13784201/matplotlib-2-subplots-1-colorbar) is an other post about the topic. And [here](https://matplotlib.org/3.1.0/gallery/subplots_axes_and_figures/colorbar_placement.html) the official examples for placing colorbars. – JohanC Apr 08 '20 at 14:26

0 Answers0