为了账号安全,请及时绑定邮箱和手机立即绑定

Python 中给定 r、theta 和 z 值的极坐标直方图

Python 中给定 r、theta 和 z 值的极坐标直方图

收到一只叮咚 2021-11-30 16:02:24
我有一个数据框,由特定磁力计站随时间的测量值组成,列对应于:它的纬度(我认为是半径)它的方位角在这个特定时间的测量量我想知道一种将这个数据框绘制为测量变量的极坐标直方图的方法:即像这样:我已经查看了特殊的直方图,physt但这允许我只输入 x,y 值,我对这一切感到很困惑。有人可以帮忙吗?
查看完整描述

2 回答

?
MM们

TA贡献1886条经验 获得超2个赞

使用 可以轻松计算直方图numpy.histogram2d。可以使用 matplotlib 的pcolormesh.


import numpy as np; np.random.seed(42)

import matplotlib.pyplot as plt


# two input arrays

azimut = np.random.rand(3000)*2*np.pi

radius = np.random.rayleigh(29, size=3000)


# define binning

rbins = np.linspace(0,radius.max(), 30)

abins = np.linspace(0,2*np.pi, 60)


#calculate histogram

hist, _, _ = np.histogram2d(azimut, radius, bins=(abins, rbins))

A, R = np.meshgrid(abins, rbins)


# plot

fig, ax = plt.subplots(subplot_kw=dict(projection="polar"))


pc = ax.pcolormesh(A, R, hist.T, cmap="magma_r")

fig.colorbar(pc)


plt.show()

//img1.sycdn.imooc.com//61a5dab30001fb4305300455.jpg

查看完整回答
反对 回复 2021-11-30
?
呼如林

TA贡献1798条经验 获得超3个赞

这似乎是您要查找的内容:https : //physt.readthedocs.io/en/latest/special_histograms.html#Polar-histogram


from physt import histogram, binnings, special

import numpy as np

import matplotlib.pyplot as plt


# Generate some points in the Cartesian coordinates

np.random.seed(42)


x = np.random.rand(1000)

y = np.random.rand(1000)

z = np.random.rand(1000)


# Create a polar histogram with default parameters

hist = special.polar_histogram(x, y)

ax = hist.plot.polar_map()

//img1.sycdn.imooc.com//61a5dac400016b4602770270.jpg

链接的文档包括更多带有颜色、bin 大小等的示例。


编辑:我认为这需要一些调整才能使您的数据形成正确的形状,但我认为此示例说明了库的功能,并且可以根据您的用例进行调整:


import random

import numpy as np

import matplotlib.pyplot as plt

from physt import special


# Generate some points in the Cartesian coordinates

np.random.seed(42)


gen = lambda l, h, s = 3000: np.asarray([random.random() * (h - l) + l for _ in range(s)])


X = gen(-100, 100)

Y = gen(-1000, 1000)

Z = gen(0, 1400)


hist = special.polar_histogram(X, Y, weights=Z, radial_bins=40)

# ax = hist.plot.polar_map()


hist.plot.polar_map(density=True, show_zero=False, cmap="inferno", lw=0.5, figsize=(5, 5))

plt.show()

//img1.sycdn.imooc.com//61a5dad00001397304570415.jpg

查看完整回答
反对 回复 2021-11-30
  • 2 回答
  • 0 关注
  • 145 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信