创造革命的表面 [英] Creating a Surface of Revolution

查看:120
本文介绍了创造革命的表面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3d磁盘图,这是代码:

I have a 3d plot of a disk, here is the code:

ri = 100
ra = 300
h=20

# input xy coordinates
xy = np.array([[ri,0],[ra,0],[ra,h],[ri,h],[ri,0]])
# radial component is x values of input
r = xy[:,0]
# angular component is one revolution of 30 steps
phi = np.linspace(0, 2*np.pi, 50)
# create grid
R,Phi = np.meshgrid(r,phi)
# transform to cartesian coordinates
X = R*np.cos(Phi)
Y = R*np.sin(Phi)
# Z values are y values, repeated 30 times
Z = np.tile(xy[:,1],len(Y)).reshape(Y.shape)


fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')

ax.set_zlim(0,200)
ax.plot_surface(X, Y, Z, alpha=0.5, color='grey', rstride=1, cstride=1)

我得到了一个不错的图:

I get this nice plot:

我有这个情节:

Further I have this plot:

代码为:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

arr = np.array([[100, 15],
               [114.28, 17],
               [128.57, 18],
               [142.85, 19],
               [157.13, 22],
               [171.13, 24],
               [185.69, 25],
               [199.97, 27],
               [214.25, 28],
               [228.53, 30],
               [242.81, 31],
               [257.09, 35],
               [271.37, 36],
               [288.65, 37],
               [300, 38]])

#interpolating between the single values of the arrays
new_x = np.concatenate([np.linspace(arr[i,0],arr[i+1,0], num=50)
                        for i in range(len(arr)-1)])

new_y = np.interp(new_x, arr[:,0], arr[:,1])
t=np.arange(700)
p = plt.scatter(new_x,new_y,c=t, cmap="jet")

#inserting colorbar
cax, _ = mpl.colorbar.make_axes(plt.gca(), shrink=0.8)
cbar = mpl.colorbar.ColorbarBase(cax, cmap='jet', label='testvalues',
                       norm=mpl.colors.Normalize(15, 40))
plt.show()



<现在我的问题是:
有没有办法将此2d图形绘制到我的3d环境中?还可以通过围绕中点旋转这些线(点)来创建曲面吗?我以与对磁盘相同的方式进行了尝试,但是失败了,因为我认为我需要闭合轮廓?这是一张可以更好地理解我想要的图片:

Now my question: Is there a way to plot this 2d graph into my 3d environment? Further is it possible to create a surface out of this line (points) by rotating them around the middlepoint ? I tried it the same way like I did it with my disk but I failed because I think I need a closed contour ? Here is a picture to understand better what I want:

推荐答案

我不确定您要如何包含2d图,所以下面是您如何将其作为旋转的表面。

I'm not sure how you want to include your 2d plot, so here's how you do it as a surface of revolution.

您的 new_x 对应于径向距离, new_y 对应于高度。因此,我们需要生成一个角度数组以生成圆锥体:

Your new_x corresponds to radial distance, new_y corresponds to height. So we need to generate an array of angles for which to generate the "cone":

from matplotlib import cm

tmp_phi = np.linspace(0,2*np.pi,50)[:,None] # angle data
linesurf_x = new_x*np.cos(tmp_phi)
linesurf_y = new_x*np.sin(tmp_phi)
linesurf_z = np.broadcast_to(new_y, linesurf_x.shape)

linesurf_c = np.broadcast_to(t, linesurf_x.shape) # color according to t
colors = cm.jet(linesurf_c/linesurf_c.max()) # grab actual colors for the surface
ax.plot_surface(linesurf_x, linesurf_y, linesurf_z, facecolors=colors,
                rstride=1, cstride=1)

结果:

这篇关于创造革命的表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆