0

I want to get a 2D density plot by using "contourf plot" tool in Python, but the result shows two "white noise" regions.

enter image description here

The color of these regions should be the same with the color nearby, so I think this is because of the rendering problem. How to solve this problem?

There seems no errors in my database, because if I plot these same data on a 3D sphere, then the result shows in a normal way.

Front:

enter image description here

Back:

enter image description here

Here are my codes of 2D plot:

x = np.load('x.npy')   
y = np.load('y.npy')   
z = np.load('z.npy')

fig = plt.figure()
plt.figure(figsize=(6,2.75),dpi=200,frameon=True)
cm = plt.cm.get_cmap('jet')
plt.contourf(x,y,z,500,cmap=cm)
cbar = plt.colorbar()
tick_locator = ticker.MaxNLocator(nbins=3)
cbar.ax.tick_params(labelsize=20)
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
cbar.locator = tick_locator
cbar.update_ticks()
plt.tight_layout()
plt.gca().invert_yaxis() 
plt.show()

Here are my data:

x=[[0.         0.02108451 0.04216903 ... 3.09942362 3.12050814 3.14159265]
[0.         0.02108451 0.04216903 ... 3.09942362 3.12050814 3.14159265]
[0.         0.02108451 0.04216903 ... 3.09942362 3.12050814 3.14159265]
...
[0.         0.02108451 0.04216903 ... 3.09942362 3.12050814 3.14159265]
[0.         0.02108451 0.04216903 ... 3.09942362 3.12050814 3.14159265]
[0.         0.02108451 0.04216903 ... 3.09942362 3.12050814 3.14159265]]

y=[[-3.14159265 -3.14159265 -3.14159265 ... -3.14159265 -3.14159265
-3.14159265]
[-3.09942362 -3.09942362 -3.09942362 ... -3.09942362 -3.09942362
-3.09942362]
[-3.0572546  -3.0572546  -3.0572546  ... -3.0572546  -3.0572546
-3.0572546 ]
...
[ 3.0572546   3.0572546   3.0572546  ...  3.0572546   3.0572546
3.0572546 ]
[ 3.09942362  3.09942362  3.09942362 ...  3.09942362  3.09942362
3.09942362]
[ 3.14159265  3.14159265  3.14159265 ...  3.14159265  3.14159265
3.14159265]]


z=[[0.00085484 0.00069078 0.00055568 ... 0.00055568 0.00069078 0.00085484]
[0.00085484 0.00069092 0.0005559  ... 0.0005559  0.00069092 0.00085484]
[0.00085484 0.00069131 0.00055655 ... 0.00055655 0.00069131 0.00085484]
...
[0.00085484 0.00069131 0.00055655 ... 0.00055655 0.00069131 0.00085484]
[0.00085484 0.00069092 0.0005559  ... 0.0005559  0.00069092 0.00085484]
[0.00085484 0.00069078 0.00055568 ... 0.00055568 0.00069078 0.00085484]]
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
F-n
  • 11
  • 3
  • Could you share the code/data that you used to produce the image? My guess is that in those regions the data contains inf's and these just get rendered as white (i.e. they are treated as masked regions). – Matt Pitkin Jun 06 '23 at 08:03
  • Hi, welcome to StackOverflow. Please take the [tour](https://stackoverflow.com/tour) and learn [How to Ask](https://stackoverflow.com/help/how-to-ask). In order to get help, you will need to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). If your question includes a Pandas DataFrame, please provide a [reproducible pandas example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – alec_djinn Jun 06 '23 at 08:09
  • Hello, thanks for your answers. The data I checked that does not contains 'inf'. I added my codes. @Matt Pitkin – F-n Jun 06 '23 at 09:36
  • [How to plot 2D Density](https://stackoverflow.com/questions/24119920/how-to-plot-a-density-map-in-python) reposted from a link-only [answer](https://stackoverflow.com/a/76412655/7758804) by [RMC](https://stackoverflow.com/users/21725086/rmc) – Trenton McKinney Jun 06 '23 at 15:52

0 Answers0