我正在使用 Python 2.7 处理从频谱分析仪获得的实时数据图。
实时绘图工作得非常好,并在极坐标图中连续绘制数据。
我更改了 y 数据的标签,它指的是半径。
plt.yticks((0, 30000000, 230000000, 750000000, 1000000000, 1500000000), ( 0, '30MHz', '230MHz', ' 0.75GHz', '1GHz', ' 1.5GHz') )
Run Code Online (Sandbox Code Playgroud)
这将在每个标签上给我一条网格线。
我想增加这些网格线(虚线)的粗细,以便更好地看到它们,因为它们被颜色覆盖。
我希望你可以帮助我。如果您需要更多代码,我很乐意与您分享更多代码。
这是我的情节的一个例子:
编辑
虽然问题已经得到解答(谢谢汤姆),但我想与您分享一些有用的命令。
我再次谷歌搜索,发现你可以向 grid() 添加更多关键字
grid( color = 'r', linestyle = '-', linewidth = 3 )
Run Code Online (Sandbox Code Playgroud)
color实际上非常明显,但linestyle = '-'已经画了线。
我正在尝试转换具有相同中心的多个圆圈的图像,从笛卡儿到极地(这样新图像将是圆形而不是圆形,请参见下图),这样就可以了以下代码:
[r, c] = size(img);
r=floor(r/2);
c=floor(c/2);
[X, Y] = meshgrid(-c:c-1,-r:r-1);
[theta, rho] = cart2pol(X, Y);
subplot(221), imshow(img), axis on;
hold on;
subplot(221), plot(xCenter,yCenter, 'r+');
subplot(222), warp(theta, rho, zeros(size(theta)), img);
view(2), axis square;
Run Code Online (Sandbox Code Playgroud)
问题是,我不明白它为什么会起作用?(显然这不是我的代码),我的意思是,当我使用函数cart2pol时,我甚至不使用图像,它只是从meshgrid函数生成的一些向量x和y ..另一个问题是,我想要某种方式有一个新的图像(不仅仅是能够用环绕功能绘制它),这是原始图像,但是通过theta和rho坐标(意思是相同的像素,但重新排列)...我甚至不确定如何问这个,最后我想要一个矩阵的图像,以便我可以对每一行求和并将矩阵转换为列向量...
我想创建一个径向条形图。我有以下 Python3 代码:
lObjectsALLcnts = [1, 1, 1, 2, 2, 3, 5, 14, 15, 20, 32, 33, 51, 1, 1, 2, 2, 3, 3, 3, 3, 3, 4, 6, 7, 7, 10, 10, 14, 14, 14, 17, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 5, 5, 6, 14, 14, 27, 27, 1, 1, 2, 3, 4, 4, 5]`
lObjectsALLlbls = ['DuctPipe', 'Column', 'Protrusion', 'Tree', 'Pole', 'Bar', 'Undefined', 'EarthingConductor', 'Grooves', 'UtilityPipe', 'Cables', 'RainPipe', 'Moulding', 'Intrusion', 'PowerPlug', 'UtilityBox', 'Balcony', …Run Code Online (Sandbox Code Playgroud) 我试图在 python 中比较风玫瑰,但这很困难,因为我无法弄清楚如何在所有地块上制作相同的比例。其他人在这里问了同样的问题windrose.py 使用的自定义百分比比例, 但没有回答。
示例代码:
from windrose import WindroseAxes
import numpy as np
import matplotlib.pyplot as plt
wind_dir = np.array([30,45,90,43,180])
wind_sd = np.arange(1,wind_dir.shape[0]+1)
bins_range = np.arange(1,6,1) # this sets the legend scale
fig,ax = plt.subplots()
ax = WindroseAxes.from_ax()
Run Code Online (Sandbox Code Playgroud)
下面的 bin_range 设置条形比例,但我需要更改 y 轴频率比例,以便可以将其与具有不同数据的其他风玫瑰进行比较。
ax.bar(wind_dir,wind_sd,normed=True,bins=bins_range)
Run Code Online (Sandbox Code Playgroud)
这个 set_ylim 似乎确实有效,但 yaxis 刻度不会改变
ax.set_ylim(0,50)
Run Code Online (Sandbox Code Playgroud)
下面的这个 set_ticks 行没有做任何事情,我不知道为什么
ax.yaxis.set_ticks(np.arange(0,50,10))
ax.set_legend()
plt.show()
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写两个函数来将笛卡尔坐标转换为球坐标,反之亦然。以下是我用于转换的方程式(也可以在此维基百科页面上找到):
和
这是我的spherical_to_cartesian功能:
def spherical_to_cartesian(theta, phi):
x = math.cos(phi) * math.sin(theta)
y = math.sin(phi) * math.sin(theta)
z = math.cos(theta)
return x, y, z
Run Code Online (Sandbox Code Playgroud)
这是我的cartesian_to_spherical功能:
def cartesian_to_spherical(x, y, z):
theta = math.atan2(math.sqrt(x ** 2 + y ** 2), z)
phi = math.atan2(y, x) if x >= 0 else math.atan2(y, x) + math.pi
return theta, phi
Run Code Online (Sandbox Code Playgroud)
并且,这是驱动程序代码:
>>> t, p = 27.500, 7.500
>>> x, y, z = spherical_to_cartesian(t, p)
>>> print(f"Cartesian coordinates:\tx={x}\ty={y}\tz={z}")
Cartesian coordinates: x=0.24238129061573832 …Run Code Online (Sandbox Code Playgroud) python geometry polar-coordinates cartesian-coordinates spherical-coordinate
我试图在 matplotlib 中将一整年的数据绘制为极坐标图,但无法找到任何此类示例。我设法根据这个线程转换了熊猫的日期,但我无法将我的头围绕(几乎)y 轴或 theta。
这是我走了多远:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd
times = pd.date_range("01/01/2016", "12/31/2016")
rand_nums = np.random.rand(len(times),1)
df = pd.DataFrame(index=times, data=rand_nums, columns=['A'])
ax = plt.subplot(projection='polar')
ax.set_theta_direction(-1)
ax.set_theta_zero_location("N")
ax.plot(mdates.date2num(df.index.to_pydatetime()), df['A'])
plt.show()
Run Code Online (Sandbox Code Playgroud)
这给了我这个情节:

减少日期范围以了解发生了什么
times = pd.date_range("01/01/2016", "01/05/2016")我得到了这个图:

我认为该系列的开头在 90 到 135 之间,但是我如何“重新映射”它以便我的年份日期范围在北原点开始和结束?
下面的代码有效,但我认为每个重复周期都会过度绘制原始点。我希望它从原点开始,每个重复循环,有一个清晰的情节。在许多解决此问题的方法中,我尝试在 init 和 update 函数中插入 ax.clear();没有效果。我在代码中留下了我认为会重置 ln,艺术家的内容;同样,这不是我正在寻找的解决方案。我会很感激在这个玩具示例中重新启动每个循环的正确方法是什么的一些指导,以便在应用于我更复杂的问题时,我不会招致累积处罚。如果传递数组,这在刷新方面效果很好......感谢您的帮助。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation, writers
#from basic_units import radians
# # Set up formatting for the movie files
# Writer = writers['ffmpeg']
# writer = Writer(fps=20, metadata=dict(artist='Llew'), bitrate=1800)
#Polar stuff
fig = plt.figure(figsize=(10,8))
ax = plt.subplot(111,polar=True)
ax.set_title("A line plot on a polar axis", va='bottom')
ax.set_rticks([0.5, 1, 1.5, 2]) # fewer radial ticks
ax.set_facecolor(plt.cm.gray(.95))
ax.grid(True)
xT=plt.xticks()[0]
xL=['0',r'$\frac{\pi}{4}$',r'$\frac{\pi}{2}$',r'$\frac{3\pi}{4}$',\
r'$\pi$',r'$\frac{5\pi}{4}$',r'$\frac{3\pi}{2}$',r'$\frac{7\pi}{4}$']
plt.xticks(xT, xL)
r = []
theta = [] …Run Code Online (Sandbox Code Playgroud) 我正在创建一个极坐标图,显示成对组数据行进方向的直方图。更具体地说,不同组的兄弟姐妹之间的方向传递。
这是一个模拟:
mockdf <- data.frame(dir = as.numeric( runif( 1000, -pi/2, pi) ),
ID = sample(letters[1:2], 1000, TRUE))
ggplot(data=mockdf, aes(x=mockdf$dir)) +
coord_polar(theta = "x", start = pi, direction = 1) +
scale_fill_manual(name = "Sibling", values=c("black", "White")) +
geom_histogram(bins=32, aes(fill=mockdf$ID), color= "black") +
facet_wrap(~mockdf$ID) +
scale_y_continuous("Number of reloactions", limits = c(-8,30)) +
scale_x_continuous(limits = c(-pi,pi), breaks = c(0, pi/4, pi/2, 3*pi/4,
pi, -3*pi/4, -pi/2, -pi/4),
labels = c("N", "NE", "E", "SE", "S", "SW", "W", "NW"))
Run Code Online (Sandbox Code Playgroud)

我想将 0、10、20、30 的 y 轴标签移动到网格本身上(即沿着 SW 方向),但这样做有困难。有谁知道我该怎么做?
我有磁盘模拟数据和 .dat 文件中的快照。我只想绘制一个但在极坐标中。
我有:
rho = np.fromfile(filename).reshape(128,384)
plt.imshow(np.log10(rho),origin='lower',cmap="Oranges",aspect='auto')
plt.colorbar()
plt.show()
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
忽略颜色和 cmap。它们不是同一个模拟。仅寻找圆盘形式。
我有一个数据框,其中包含特定磁力计站随时间的测量结果,列对应于:
我想知道一种方法将此数据框绘制为测量变量的极坐标直方图:即类似这样的:
我已经查看了特殊的直方图,physt但这允许我只输入 x,y 值,我对这一切感到非常困惑。
有人可以帮忙吗?
python ×7
matplotlib ×6
python-3.x ×2
animation ×1
axis-labels ×1
bar-chart ×1
geometry ×1
ggplot2 ×1
image ×1
imshow ×1
matlab ×1
plot ×1
r ×1
time-series ×1