How to convert a grid-like matplotlib plot to a smooth gradient like surface?

人走茶凉 提交于 2021-02-04 16:24:43

问题


I am trying to plot a 2D numpy array using imshow function from matplotlib.pyplot (it is the plot of a U-matrix generated using the codebook of a self organizing map).

The plot is being generated by the following line:

matplotlib.pyplot.imshow(umat, cmap=plt.cm.get_cmap('RdYlBu_r'), alpha=1)

Here, umat is the 2D numpy array that I am trying to plot. Here is the plot that is generated:

It shows each node (point) as a distinct square.

I would like to generate something like this

,

showing a smooth surface, however I am unable to find a way to do it. Could someone show how it could be done?


回答1:


If you want to use imshow, you can try different interpolation methods, see https://matplotlib.org/examples/images_contours_and_fields/interpolation_methods.html

Example: ax.imshow(grid, interpolation=interp_method, cmap='viridis') where interp_method is one of

methods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos']


来源:https://stackoverflow.com/questions/48636157/how-to-convert-a-grid-like-matplotlib-plot-to-a-smooth-gradient-like-surface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!