0

I managed to plot a colorbar for a contourplot, but the colors are displayed as discete stripes instead of a continous spectrum. The colorbar is based on the data the contourplot, which I do not want to be displayed as continous.

I have six contour-plots as subplots in one figure. The value scale for all is from 0 to 1. At the right side, the colorbar is attached to two axes of the subplots (ax3, ax6) based on the data from one of the subplots:

Z = ax6.contour(data_5["z"], extent=[0*5, 10*5, 0*5, 7*5],levels=20)

cbar = fig.colorbar(Z, ax=[ax3,ax6], shrink=0.8, pad=0.01, aspect=10)

fig.subplots_adjust(right=0.8)

Is there a parameter I can add to have the colors in the colorbar be displayed as continuum or another way to achieve this?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • `fig.colorbar(plt.cm.ScalarMappable(norm=Z.norm, cmap=Z.cmap), ticks=Z.levels)` – JohanC Jan 23 '23 at 14:20
  • Welcome to Stack Overflow! Please do not add answers to the question body itself. Instead, you should add it as an answer. [Answering your own question is allowed and even encouraged](https://stackoverflow.com/help/self-answer). In this case, either ask for it to be reopened, such that you can add your answer here, or post your answer at either of the duplicate posts. – Adriaan Jan 25 '23 at 10:35

0 Answers0