亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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()

http://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()

http://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()

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

查看完整回答
反對 回復 2021-11-30
  • 2 回答
  • 0 關注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號