I am trying to plot 2 distinct colormeshes on the same figure. They are mutually exclusive, so there are no overlaps. This is my code:

sm3 = ScalarMappable (cmap='Blues', norm=Normalize(vmin=0, vmax=1))
p3 = ax.pcolormesh ( E_mm_n, E_mm_a, Z_gg, cmap="Blues"   , shading="auto") 
sm4 = ScalarMappable (cmap='Purples', norm=Normalize(vmin=0, vmax=1))
p4 = ax.pcolormesh ( E_mm_n, E_mm_a, Z_gc, cmap="Purples" , shading="auto") 

Everytime I make this plot, all I see is the plot defined by p4. I never see the information in p3. How can I make sure both colormeshes are visible? Also, Z_gg and Z_gc are mutually exclusive, so they should be right next to one another, with no overlaps.

With the above code, I see the following figure: enter image description here

When I comment out the sm4 and p4 lines, i get the following figure: enter image description here

How can i get both the blue and purple on the same plot? I would appreciate any advice you have for me!


1 Answer 1


I think the issue is that your E_mm_n, E_mm_a parameters are the same in both calls, and so it thinks the first QuadMesh is behind the second. When I do this

Z = np.random.rand(6, 10)
x = np.arange(-0.5, 10, 1)  # len = 11
y = np.arange(4.5, 11, 1)  # len = 7
X, Y = np.meshgrid(x, y)

X1 = X + 0.4 * Y  # tilt the coordinates.
Y1 = Y + 0.3 * X

X2 = X + 0.4 * Y  # tilt the coordinates.
Y2 = Y + 0.3 - X

ax.pcolormesh(X1, Y1, Z, cmap="Purples")
ax.pcolormesh(X2, Y2, Z, cmap="Blues")    

It displays enter image description here

  • $\begingroup$ Thank you for your answer @brewmaster321! I do need to plot them on the same plot. How can I only plot the subset in that case? $\endgroup$
    – megamence
    Apr 12, 2023 at 12:39
  • $\begingroup$ The X and Y coordinates for the two calls to pcolormesh need to be disjoint - right now they overlap completely. From the docs X and Y are the coordinates of the corners of quadrilaterals of a pcolormesh - it's basically drawing one quadilateral on top of the other. If you can partition your E_mm_n, E_mm_a, into one subset for the blue data points and one subset for the purple that should do the trick. $\endgroup$ Apr 12, 2023 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.