作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想使用以下数组为极坐标创建网格。
R = 1.15
r = numpy.linspace(R,5,100)
theta = numpy.linspace(0,2*numpy.pi,145)
我这样试过,使用 numpy
:
X,Y=numpy.meshgrid(r*numpy.cos(theta),r*numpy.sin(theta))
但是我收到了这个错误:
ValueError: operands could not be broadcast together with shapes (100,) (145,)
如何生成网格并显示点?
最佳答案
如果您只想在极坐标网格上指定坐标 r
和 theta
的两个二维数组,请不要转换为笛卡尔坐标系。
澄清一下,您看到的错误是因为您无法在两个形状不等的数组之间执行逐元素乘法,而这正是您所拥有的。
你应该这样调用它:
radius_matrix, theta_matrix = numpy.meshgrid(r,theta)
然后您可以通过键入以下内容转换为笛卡尔坐标(如果确实需要):
X = radius_matrix * numpy.cos(theta_matrix)
Y = radius_matrix * numpy.sin(theta_matrix)
可以立即在极坐标网格上进行可视化,例如使用matplotlib:
import matplotlib.pyplot as plt
ax = plt.subplot(111, polar=True)
ax.plot(theta_matrix, radius_matrix, color='r', ls='none', marker='.')
看看 polar plot demo如果你想要另一个例子。
或者,您可以通过绘制我们之前在笛卡尔网格上获得的笛卡尔坐标来绘制您制作的极坐标网格:
plt.plot(X,Y, 'r. ')
plt.show()
关于python - 为极坐标创建网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28926813/
我正在寻找绘制极坐标数据的替代方法。我需要实现像 this 这样的图表具有动态选项,例如 this . 非常感谢您的帮助! 最佳答案 我个人需要这些: Highcharts JS canvasXpre
我是一名优秀的程序员,十分优秀!