如何在极坐标中绘制条形图

时间:2020-05-02 01:34:56

标签: python matplotlib mplot3d

我正在用极坐标教积分。为了将其引入笛卡尔坐标中,我使用bar3d演示了如何在一个方向上进行精炼,然后在另一个方向上根据黎曼和求出积分。

现在,我想在极坐标中执行此操作。我找不到办法。我可以找到使用极坐标通过平滑插值(https://matplotlib.org/3.1.1/gallery/mplot3d/surface3d_radial.html)在3d中绘制表面的方法,但是我想显示在每个表面元素上恒定的条形,在此我可以控制条形的宽度。

这是执行笛卡尔直方图的代码。我想在极坐标中绘制相同的函数(x ^ 2 + y ^ 2):

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax1 = plt.axes(projection='3d')


Nx=5
Ny=20
# fake data
xm = 2
ym=1
_x = np.linspace(0,xm*(1-1/Nx), Nx)
_y = np.linspace(0,ym*(1-1/Ny), Ny)
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()

top = x*x + y*y
bottom = np.zeros_like(top)
width = xm/Nx
depth = ym/Ny

ax1.bar3d(x, y, bottom, width, depth, top, shade=True)
ax1.set_title('$x^2+y^2$')
#ax1.xlabel('$x$')
#ax1.ylabel('$y$')
#ax2.bar3d(x, y, bottom, width, depth, top, shade=False)
#ax2.set_title('Not Shaded')
ax1.set_xlabel('$x$', fontsize=20)
ax1.set_ylabel('$y$', fontsize=20)
plt.show()

enter image description here

0 个答案:

没有答案