0

I am trying to plot Two-dimensional distribution with Gaussian smoothing for all the data points. Here is my sample data. I would like to plot like this paper figure.

Two-dimensional distribution of Hα emitters in the HSC DEEP2-3 field. The small circles indicate the positions of Hα emitters. The colored contours indicate 1 σ, 1.5 σ, 2 σ, 3 σ, 4 σ, 5 σ above the mean density distribution computed with all member galaxies (i.e., the photo-z-selected sample and Hα emitters). Here we apply Gaussian smoothing for all the data points with σ ∼ 0.75 Mpc, and co-add the tail of the Gaussian wing at each position. The two yellow pentagons indicated as CL1 and CL2 show the locations of two CAMIRA clusters at z ∼ 0.4 identified by the red-sequence finder method by Oguri et al. (2018). Possible strong over-densities are also seen at the north-east and at the south edge of the field (CL3 and CL4). They are also likely to be in the same structure as CL1/CL2, but CL3/CL4 are not identified as CAMIRA clusters, and unfortunately there are no galaxies with spectroscopic redshift available around CL3/CL4 region. The large gray circles show the object masks; we show only large masks with radius of >2΄ for clarity. (Color online)

[Two-dimensional distribution of Hα emitters(galaxies). The small circles indicate the positions of Hα emitters. The colored contours indicate 1 σ, 1.5 σ, 2 σ, 3 σ, 4 σ, 5 σ above the mean density distribution computed with all member galaxies (i.e., the photo-z-selected sample and Hα emitters). Here we apply Gaussian smoothing for all the data points with σ ∼ 0.75 Mpc, and co-add the tail of the Gaussian wing at each position. The large gray circles show the object masks; we show only large masks with radius of >2΄ for clarity. (Color online)]

I am trying to plot the same plot with my data. But I am not able to plot like this.

Here is my code

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
import scipy as sp
import scipy.ndimage
from astropy.table import Table
import branca
import pandas as pd
%matplotlib inline

#DATA
data=Table.read('s_data.fits')
density_mean=np.mean(data['density'])
std=np.std(data['density'])
vmin   = density_mean+std
vmax   = density_mean+(5*std)
levels = len(colors)
cm     = branca.colormap.LinearColormap(colors, vmin=vmin, vmax=vmax).to_step(levels)

x_orig = data['ra']
y_orig = data['dec']
z_orig = data['density']

# Make a grid
x_arr          = np.linspace(np.min(x_orig), np.max(x_orig), 500)
y_arr          = np.linspace(np.min(y_orig), np.max(y_orig), 500)
 
#WHEN I CHANGE THE VALUE FROM 500 to ANOTHER IT DOESN'T COVER ALL THE AREA. WHAT WILL BE THE APPROPRIATE VALUE FOR THIS?

x_mesh, y_mesh = np.meshgrid(x_arr, y_arr)

# Grid the values
z_mesh = griddata((x_orig, y_orig), z_orig, (x_mesh, y_mesh), method='linear')
# Gaussian filter the grid to make it smoother
sigma = [5, 5]
z_mesh = sp.ndimage.filters.gaussian_filter(z_mesh, sigma, mode='constant')

# Create the contour
plt.plot(data['ra'], data['dec'], 'ko', markersize=1,alpha=1)
plt.text(352.33,0.135, 'CL1',fontsize=15)  #CL1 coordinate
plt.text(352.096,0.390, 'CL2', fontsize=15) #CL2 coordinate
plt.contourf(x_mesh, y_mesh, z_mesh, levels, alpha=0.7, colors=colors, linestyles='None', 
vmin=vmin, vmax=vmax)
#plt.colorbar()
plt.gca().invert_xaxis()

And I got like this enter image description here

I know something is wrong with my data. Kindly help to get the proper figure like given in the paper. Thank you.

John Singh
  • 79
  • 1
  • 2
  • 10
  • Did you try using cmap arg in plt.contourf(). The cmap in pic seems to be custom made. You can create custom cmap using `cmap = matplotlib.LinearSegmentedColormap.from_list("mycmap", ['w','yellow','r'],N=1024)` To shift axis ticks inside the plot refer to this [question](https://stackoverflow.com/questions/47873389/matplotlib-move-tick-labels-inside-plot-area) – DataNoob Feb 12 '21 at 17:50
  • @DataNoob Thank You. But still, I am not able to get properly. There is a cut in the contour. I am not sure why is it – John Singh Feb 15 '21 at 05:49
  • Try changing the sigma for your gaussian filter `sigma = [5, 5] z_mesh = sp.ndimage.filters.gaussian_filter(z_mesh, sigma, mode='constant')` to make it smooth or check for missing values (NA) in your data and fill them using the suitable method. – DataNoob Feb 15 '21 at 09:31

0 Answers0