0

I hope this hasn't been posted before: I should plot the difference in altitude over time with a picture of a mountain. But I should only plot the colormap in a certain area (black line). I get the colormap usind a grid for 2 different years and calculating the difference in altitude.

My result:

plt.imshow(bild1, extent = [-1100,-200, 1500, 2100], cmap = "Greys_r")
plt.imshow(grid_delta, cmap = "jet", vmin = -5, vmax = 17, origin = "lower", extent = [-1100,-200,1500,2100])
plt.colorbar(boundaries = bounds, ticks = bounds)
plt.plot(studienbereich_x, studienbereich_y, "black", label="Studienbereich", linewidth = 2)
plt.xlim(-1100, -200)
plt.ylim(1500, 2100)
plt.savefig("example.png")

This is what I get: https://i.stack.imgur.com/hy5MH.jpg

This is what I should get: https://i.stack.imgur.com/xQdd7.jpg

I also tried figuring out the data points inside the area of need before interpolating the grids but in the end it didn't fit the area very well.

C.Joe
  • 51
  • 1
  • 3
  • Essentially the solution here could be similar to [this one](https://stackoverflow.com/questions/42063542/mathplotlib-draw-triangle-with-gradient-fill). Other options would be to set the pixels outside of the area of interest to nan. Make sure to share what you have tried. Also read and understand [mcve]. – ImportanceOfBeingErnest Jan 24 '18 at 17:53

1 Answers1

0

Change your code to following may solve your problem:

fig = plt.imshow(
    grid_delta,
    cmap="jet",
    vmin=-5,
    vmax=17,
    origin="lower",
    extent=[-1100,-200,1500,2100]
)
cbar = plt.colorbar(fig)

Reference: https://matplotlib.org/examples/pylab_examples/colorbar_tick_labelling_demo.html

Omar Einea
  • 2,478
  • 7
  • 23
  • 35
  • 1
    I don't see `cbar` being defined or used anywhere in OP's code. *How* exactly is this going to solve his issue? – Blue Jan 24 '18 at 19:45
  • For sure this does not answer the question. On the other hand without a [mcve] one may apparently get just any answer here. Another reason to include such example, such that potential solutions can be verified. – ImportanceOfBeingErnest Jan 25 '18 at 01:12