1

I want to plot a 2D scatter interpolation of some sensor data. I have the X, Y coordinates and the Z values. I am trying to build the same plot for several timeframes, lets say one for min 1 the other for min 2 and a third for min 3. The problem is the scale changes all the time as the Z max value always corresponds to the highest colour. I want that my Z max value to be always the same in colour in the interpolation colour. so the Max colour only appears in one of the images and does not correspond to my Z max value in each single image. Here is the code:

import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate
import pandas as pd

x = [444, 664, 0, 193, 444, 664, 0, 193, 444, 664,193]
y = [0, 0, 553, 553, 553, 553, 726, 726, 726, 726, 1107]

z = [-0.1, -0.25, 0.14, 0.45, 0.5, 0.7, -0.15, 0.27, 0.4, -0.2, 0.1]

 # Set up a regular grid of interpolation points
 xi, yi = np.linspace(min(x), max(x), 100), np.linspace(min(y), max(y), 100)
 xi, yi = np.meshgrid(xi, yi)

 # Interpolate
 rbf = scipy.interpolate.Rbf(x, y, z, function='linear')
 zi = rbf(xi, yi)


 plt.figure(figsize=(6,10))
 plt.imshow(zi, vmin=-0.25, vmax=1, origin='lower', extent=[min(x), max(x), min(y), max(y)])

 plt.contourf(xi, yi, zi, 500, cmap='jet')
 plt.scatter(x, y, c=z, cmap='jet')
 plt.colorbar()
 plt.clim(-0.25, 1)
Mr. T
  • 11,960
  • 10
  • 32
  • 54
Rui Silva
  • 11
  • 1
  • 2
  • maybe this answers your question: https://stackoverflow.com/questions/35556926/matplotlib-normalize-colorbar-python – GrimTrigger Jan 10 '21 at 13:00
  • Please be very careful with `'jet'` as a colormap for this type of data. `'jet'` shows bright yellow spots, not at the highest values but somewhere inbetween. [How bad is your colormap?](http://jakevdp.github.io/blog/2014/10/16/how-bad-is-your-colormap/) – JohanC Jan 10 '21 at 14:15
  • Did you try setting `vmin` and `vmax` in `plt.scatter(...)` similar to how it was done in `plt.imshow()`? Did you try to set explicit levels, and `vmin` and `vmax` in `plt.contourf`? Is plotting `imshow`, `contourf` and `scatter` all three on the same subplot on purpose? It seems quite difficult to understand such plot. – JohanC Jan 10 '21 at 14:21

0 Answers0