简体   繁体   中英

Plotting 3D distribution in python

I would like to plot my data in 3D like this figure(The filled circles are shown in gray scale based on the declination; darker colours mean lower declination.The dots in the R.A.-Dec. plane are the projection on the celestial plane) 在此处输入图像描述

I plot like this but I am not able to get like the given figure given above

import numpy as np, math
import matplotlib.pyplot as plt
from astropy.table import Table
from mpl_toolkits.mplot3d import Axes3D

data=Table.read('test_data.fits')
min_red=min(data['redshift'])
fig = plt.figure(figsize=(16,14))
ax = Axes3D(fig)

ax = fig.gca(projection='3d')
ax.view_init(10,30)

ax.plot(data['ra'], data['dec'], data['redshift'],'ko',markersize=5,linewidth=2)

m=ax.plot(data['ra'], data['dec'], 'ro', markersize=1, color='r', zdir='z', zs=min_red)

ax.set_xlabel('ra')
ax.set_ylabel('dec')
ax.set_zlabel('redshift')
plt.show()

But I got like this figure(the dots in Ra and Dec are the projection on the celestial plane) 在此处输入图像描述

How to plot like the first figure. Kindly do help

I think the easiest would be to use Axes3D.scatter as following:

import numpy as np, math
import matplotlib.pyplot as plt
from astropy.table import Table
from mpl_toolkits.mplot3d import Axes3D

data=Table.read('test_data.fits')
min_red=min(data['redshift'])
fig = plt.figure(figsize=(16,14))
ax = Axes3D(fig)

ax = fig.gca(projection='3d')
ax.view_init(10,30)

y=list(data['dec'])
ax.scatter(data['ra'], data['dec'], data['redshift'],'ko', c=y, cmap = 'Greys')

m=ax.plot(data['ra'], data['dec'], 'ro', markersize=1, color='r', zdir='z', zs=min_red)

ax.set_xlabel('ra')
ax.set_ylabel('dec')
ax.set_zlabel('redshift')
plt.show()

As specified in Axes3D.scatter documentation:

A color. c can be a single color format string, or a sequence of color specifications of length N, or a sequence of N numbers to be mapped to colors using the cmap and norm specified via kwargs (see below). Note that c should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. c can be a 2-D array in which the rows are RGB or RGBA, however, including the case of a single row to specify the same color for all points.

My result with the code above

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM