通常情况下,极坐标从0到π到2个π(之前2个π真的,因为它再次等于0).但是,在使用JavaScript atan2()函数时,我会得到一个不同的,奇怪的范围:
Cartesian X | Cartesian Y | Theta (?)
===========================================================
1 | 0 | 0 (0 × π)
1 | 1 | 0.7853981633974483 (0.25 × π)
0 | 1 | 1.5707963267948966 (0.5 × π)
-1 | 1 | 2.356194490192345 (0.75 × π)
-1 | 0 | 3.141592653589793 (1 × π)
-1 | -1 | -2.356194490192345 (-0.75 × π)
0 | -1 | -1.5707963267948966 (-0.5 × π … 假设我正在绘制一个像这样的复杂值:
a=-0.49+1j*1.14
plt.polar([0,angle(x)],[0,abs(x)],linewidth=5)
Run Code Online (Sandbox Code Playgroud)
给予

是否有一个设置我可以用来获得圆形的线条末端,如下例中的红线(在油漆中绘制)?

我试图ggplot2在南极周围跟踪一只鸟的踪迹.到目前为止,我得到了一个以极坐标投影的地图,我还设法正确地绘制了跟踪点,我几乎正确地将它们连接起来......但是当轨道越过国际DATE&TIME线时,ggplot2无法正确链接2个点在线的两侧.所以我正在寻找一种方法来强制ggplot以连续的方式链接点.
这是我的数据集:
Data =>
ID Date Time A1 Lat. Long.
10 12.9.2008 22:00 1 21.14092 70.98817
10 12.9.2008 22:20 1 21.13031 70.97592
10 12.9.2008 22:40 2 21.13522 70.97853
10 12.9.2008 23:00 1 21.13731 70.97817
10 12.9.2008 23:20 3 21.14197 70.97981
10 12.9.2008 23:40 1 21.14156 70.98158
10 12.9.2008 23:40 1 21.14156 70.98158
10 13.9.2008 00:00 2 21.14150 70.98478
10 13.9.2008 00:20 3 21.14117 70.98803
10 13.9.2008 00:40 1 21.14117 70.98803
10 13.9.2008 01:00 2 …Run Code Online (Sandbox Code Playgroud) 我想绘制一个抛物面f(r)= r**2作为2D极地热图.我期望的输出是
我写的代码是
from pylab import*
from mpl_toolkits.mplot3d import Axes3D
ax = Axes3D(figure())
rad=linspace(0,5,100)
azm=linspace(0,2*pi,100)
r,th=meshgrid(rad,azm)
z=(r**2.0)/4.0
subplot(projection="polar")
pcolormesh(r,th, z)
show()
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?先感谢您.
我正在试图弄清楚如何将轴附加到我的极地投影上.新添加的轴应该像环一样环绕原始极轴.
为此,我尝试使用matplotlib投影上append_axes创建的分隔符.make_axes_locatablepolarax
但是,"外部"或任何类似极性投影的append_axes参数都没有选择.我没有围绕轴的环,而是在原始轴下方获得一个新轴(见图).
有没有可以在现有极轴周围创建环形轴的替代方案?
注意,我不想将它们添加到同一个轴上,因为比例可能不同.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
plt.style.use("seaborn-white")
def synthesize(polar=False):
fig = plt.figure()
ax = fig.add_subplot(111, polar=polar)
t = np.linspace(0,2*np.pi)
r_sin = np.sin(t)
r_cos = np.cos(t)
for r in [r_sin, r_cos]:
ax.scatter(t, r, c=r, s=t*100, edgecolor="white", cmap=plt.cm.magma_r)
ax.scatter(t, -r, c=r, s=t*100, edgecolor="white", cmap=plt.cm.magma_r)
ax.set_title("polar={}".format(polar),fontsize=15)
ax.set_xticklabels([])
return fig, ax, t
# Rectilinear
fig, ax, t = synthesize(polar=False)
# Here are the plot dimensions in …Run Code Online (Sandbox Code Playgroud) 我测量了不同产品在不同角度位置的位置(在整个旋转过程中以 60 度为步长的 6 个值)。我想使用极坐标图,而不是在 0 和 360 是同一点的笛卡尔图上表示我的值。
使用matplotlib,我得到了一个蜘蛛图类型的图形,但我想避免点之间的直线,并在它们之间显示和外推值。我有一个不错的解决方案,但我希望有一个不错的“单衬”,我可以用它来对某些点进行更逼真的表示或更好的切线处理。
有没有人有想法改进我下面的代码?
# Libraries
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# Some data to play with
df = pd.DataFrame({'measure':[10, -5, 15,20,20, 20,15,5,10], 'angle':[0,45,90,135,180, 225, 270, 315,360]})
# The few lines I would like to avoid...
angles = [y/180*np.pi for x in [np.arange(x, x+45,5) for x in df.angle[:-1]] for y in x]
values = [y for x in [np.linspace(x, df.measure[i+1], 10)[:-1] for i, x …Run Code Online (Sandbox Code Playgroud) 我正在使用 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坐标(意思是相同的像素,但重新排列)...我甚至不确定如何问这个,最后我想要一个矩阵的图像,以便我可以对每一行求和并将矩阵转换为列向量...
我试图在 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
python ×7
matplotlib ×6
plot ×2
atan2 ×1
coordinates ×1
geometry ×1
ggplot2 ×1
heatmap ×1
image ×1
javascript ×1
maps ×1
matlab ×1
numpy ×1
projection ×1
r ×1
radians ×1