Dear,all
I want to calculate the number density distribution (1D or 2D) based on molecular center of mass in lammps, how can I do it?
You can probably pull something together using:

compute chunk/atom
to chunk atoms into molecules 
compute com/chunk
to produce a vector of centres of mass 
fix ave/histo
to create a histogram of centres of mass (taking into account periodic images)
Or you can do it by postprocessing a trajectory. My recommendation is to go with postprocessing since, if you were pulling together a list of LAMMPS commands like I suggested, you’d still need to test it and make sure it’s correct – for which you need a trajectory postprocessing approach anyway.
Indeed. For instance the DensityPlanar module of MAICoS allows for calculating density from the centerofmass of molecules.