I am making a colormap of a 2D numpy meshgrid:
X, Y = np.meshgrid(fields, frequencies)
cs = ax.contourf(X, Y, fields_freqs_abs_grid, cmap="viridis", N=256)
The values in fields_freqs_abs_grid, which are plotted by color, have already been logarithmically scaled.
The colormap produced by python's matplotlib is coarse -- it scales over 8 colors even though I use "N=256" for the number of RGB pixels. Increasing N to 2048 did not change anything. A plot using the MatLab language on the same data produces a colormap with significantly higher color resolution. How do I increase the number of colors mapped in Python?
Thank you!
Warren Weckesser's comments definitely works and can give you a high resolution image. I implemented his idea in the example below.
In regarding to use
contourf()
, I'm not sure if this is a version dependent issue, but in the most recent version,contourf()
doesn't have a kwarg forN
.As you can see in the document, you want to use
N
as an arg (in syntax:contourf(X,Y,Z,N)
) to specify how many levels you want to plot rather than the number of RGB pixels.contourf()
draws filled contours and the resolution depends on the number of levels to draw. YourN=256
won't do anything andcontourf()
will automatically choose 7 levels.The following code is modified from the official example, comparing resolutions with different
N
. In case there is a version issue, this code gives the following plot withpython 3.5.2; matplotlib 1.5.3
: