0

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) enter image description here

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) enter image description here

How to plot like the first figure. Kindly do help

John Singh
  • 79
  • 1
  • 2
  • 10
  • Possible duplicate: https://stackoverflow.com/questions/14995610/how-to-make-a-4d-plot-with-matplotlib-using-arbitrary-data – Mr. T Jan 21 '21 at 11:52
  • @Mr.T It is a different question from the one which you commented. I would like to change the shape of how the 3D distribution is seen(my first figure). But I am not able to plot like that. I want to plot in the same way as the first figure – John Singh Jan 21 '21 at 12:13
  • What is "the same way", what does "shape of how it is seen" mean? The images differ in many aspects. Do you want to change the [viewing angle](https://stackoverflow.com/q/47610614/8881141)? – Mr. T Jan 21 '21 at 12:18
  • @Mr.T Yes, I would like to change the viewing angle just like the first figure. Actually, X, Y and Z are the same (The first figure used another transformation but it is same as X is RA, y is DEC and z is Redshift [the first figure convert the redshift to distance so it is similar]. I would like to plot my figure in same viewing angle and without the grid – John Singh Jan 21 '21 at 12:23
  • This tells you how to make specific panes invisible: https://stackoverflow.com/q/44001613/8881141 With this information, you should be able to recreate the desired output. – Mr. T Jan 21 '21 at 12:29

1 Answers1

0

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

EKLZ
  • 33
  • 5
  • I plot like this also. I want to plot like the same viewing angle. As you can see we can see the corner (like the corner of the wall) in my plot but we cannot see anything like that in the first figure of my question. – John Singh Jan 21 '21 at 12:26
  • Ok, I thought the question was about the dots color, you'll be able to find your answer there : https://stackoverflow.com/questions/44001613/matplotlib-3d-surface-plot-turn-off-background-but-keep-axes – EKLZ Jan 21 '21 at 12:29