给定r,theta和z值的Python极坐标直方图 [英] Polar histogram in Python for given r, theta and z values

查看:61
本文介绍了给定r,theta和z值的Python极坐标直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据帧,该数据帧由特定磁强计站随时间的测量结果组成,其列对应于:

  • 它的纬度(我认为是半径)
  • 它的方位角
  • 在特定时间测量的数量

我想知道一种将这个数据框绘制为测量变量的极坐标直方图的方法:即像这样:

我查看了 physt 中的特殊直方图,但这允许我只输入 x,y 值,我对此感到非常困惑.

有人可以帮忙吗?

解决方案

使用

I have a dataframe consisting of measurements from a particular magnetometer station over time, with columns corresponding to:

  • its latitude (which I think of as a radius)
  • its azimuthal angle
  • a measured quantity at this specific time

I was wondering of a way to plot this dataframe as a polar histogram for the measured variable: ie something like this:

I have looked at the special histogram in physt but this allows me to only put in x,y values and I'm quite confused by it all.

Could anybody help?

解决方案

Calculating a histogram is easily done with numpy.histogram2d. Plotting the resulting 2D array can be done with matplotlib's 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()

这篇关于给定r,theta和z值的Python极坐标直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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