0

Was able to draw polar chart (code below) by using matplotlib.pyplot and trying to draw 3D chart from this data by using Axes3D, but not getting a clue how to plot.

Using python 2.7.

import numpy as np
import matplotlib.pyplot as plt

fig   = plt.figure()
ax1   = fig.add_subplot(121, polar=True)
ax2   = fig.add_subplot(122, polar=True)
h     = [-20, -15, -10,  -5,   0,  -3, -10, -16, -20 ]         # horizontal data
v     = [  0,  -5, -15, -18, -20, -10,  -5,  -1,   0 ]         # vertical data
theta = np.linspace( 0, -2 * np.pi, 9 )                        # theta

x_range_1 = [ 90,  45,   0,  -45, -90, -135, 180, 135 ]
x_range_2 = [  0, -45, -90, -135, 180,  135,  90,  45 ]

ax1.set_rmax(0)
ax1.set_rmin(-40)
ax1.set_yticks(range(-40, 0, 5))
ax1.set_xlim(135)
ax1.set_xticklabels(x_range_1)

ax2.set_rmax(0)
ax2.set_yticks(range(-40, 0, 5))
ax2.set_xlim(135)
ax2.set_xticklabels(x_range_2)

ax1.grid( True )
ax1.plot( theta, h, label = 'horizontal' )

ax2.grid( True )
ax2.plot( theta, v, label = 'vertical' )

plt.show()

Below is the 3D code i tried.. ax1 displays horizontal polar chart and ax2 is 3D (but, i am sure that 3D is not something right..)

from mpl_toolkits.mplot3d import axes3d
import numpy as np
import matplotlib.pyplot as plt

fig   = plt.figure()
ax1   = fig.add_subplot(121, polar=True)
ax2   = fig.add_subplot(122, projection='3d')
h     = [ -20, -15, -10,  -5,   0,  -3, -10, -16, -20 ]        # horizontal data
v     = [   0,  -5, -15, -18, -20, -10,  -5,  -1,   0 ]        # vertical data
theta = np.linspace( 0, -2 * np.pi, 9 )                        # theta

x_range_1 = [ 90,  45,   0,  -45, -90, -135, 180, 135 ]
x_range_2 = [  0, -45, -90, -135, 180,  135,  90,  45 ]

ax1.set_rmax(0)
ax1.set_rmin(-40)
ax1.set_yticks(range(-40, 0, 5))
ax1.set_xlim(135)
ax1.set_xticklabels(x_range_1)

ax1.grid( True )
ax1.plot( theta, h, label = 'horizontal' )

ax2.grid( True )
R,P = np.meshgrid( h, theta ) 
X,Y = R * np.cos(P), R * np.sin(P)               # transform [R,P] to cartesian system 
Z   = v                                          # ( ( R**2 - 1 )**2 )

ax2.plot_surface( X, Y, Z, label = '3d' )

plt.show()

Below is the output of above program https://docs.google.com/file/d/0Bw8wTgcsK-k8d3JvRmVuUUxfSE0/edit CURRENT_OUTPUTs

Below is the kind of diagram i am actually expecting, EXPECTED_OUTPUT https://docs.google.com/file/d/0Bw8wTgcsK-k8aFZhcnZPYmJTdkk/edit

Thanks in advance for your help.

user3666197
  • 1
  • 6
  • 50
  • 92
Som
  • 1,467
  • 13
  • 11
  • You need to specify more clearly what you are trying to do. What do you want to plot in the 3D axes? – hitzg Oct 30 '14 at 08:34
  • How to convert above 2d plot into 3d? – Som Oct 30 '14 at 09:01
  • An example would help. If you are using your h and v datasets only, those will appear on two linearly independent planes (ellipses) of the sphere. Would you then connect those planes with a straight line / curve / surface along the generatrix? Include a picture of what you expect to get, please. – giosans Oct 30 '14 at 15:43
  • hitzg, giosans, thanks for your replies. i updated post by details and also links to point images. thanks. – Som Oct 30 '14 at 18:03
  • @Som, you may be interested in a surface-plot parametrisation, example of which ( for a trivial, spherical case ) also in R-phi-theta [u,v] polar coordinate system parametrisation and necessary data-structures elaboration **in >>>** http://stackoverflow.com/q/26587518/3666197 – user3666197 Oct 30 '14 at 19:21
  • @user3666197, I just followed the sample from the link you mentioned, but i am getting a complete spherical shape.. my actual shape i suppose to get is not a complete spherical, but the one i attached above.. am i doing something wrong? – Som Oct 30 '14 at 20:04
  • Certainly, as your code is right this second, your Z is a 1D array, whereas X and Y are 2D, so your data dimensions don't make any sense anyway. Also, you obviously aren't going to get anything as complicated as the picture you are "expecting" with only 9 data points. – Ajean Oct 30 '14 at 20:16
  • @Som, exactly, the value of the referred example is to learn the (R)[u,v] parametrisation then mapped onto [X,Y,Z]-matrices to get surface plot in 3D. – user3666197 Oct 30 '14 at 20:27
  • @Ajean, the "expecting" chart is with 360 datapoints and i am not sure what tool used for that. here, for the sample, i took only 9 points.. can you help me to make Z axis stright? thanks. – Som Oct 30 '14 at 20:28
  • I can't, really, because I have no idea what you're actually looking for. You said you followed the example @user3666197 shared and got a sphere - try to *understand* the example and apply it to what you want. – Ajean Oct 30 '14 at 20:31
  • 1
    Prototyping **`.plot_surface()`** with just 9x9x9 datapoints is rather brutal minimalism. Check the expected number of datapoints in your red 3D-surface meshing and do not hesitate to overload numpy/matplotlib with fine-grained parametrisation 100x100x100 or 500x500x500, it can handle a lot and your visualisation will get closer to the real-surface. – user3666197 Oct 30 '14 at 20:45
  • I am able to draw radar plot with horizontal data and theta. Similarly I am able to draw radar plot with Vertical data and theta. Now the requirements is, I will have to create a 3D plot by combining horizontal data, Vertical Data & theta. I am expecting the 3D plot should look similar to horizontal radar plot say @ zero degree perspective and should look similar to vertical radar plot say @ 90 degree perspective but I am nowhere near to what I want... :( – Som Nov 04 '14 at 04:13

0 Answers0