【问题标题】:Matplotlib: Making Polar Plot with Logarithmic Angular AxisMatplotlib:使用对数角轴制作极坐标图
【发布时间】:2021-09-06 20:43:37
【问题描述】:

我想绘制一些圆轴来绘制老式圆形计算尺的图稿。在几乎每个示例中,极坐标图都有一个度数或弧度的角轴。我发现了一个将标签更改为时钟 (1 - 12) 的示例,但我不知道如何将该技术扩展到对数刻度。

我可以以线性方式绘制所需的轴,因为我看到了制作对数径向轴的示例。但我找不到将对数刻度应用于角度 theta 轴的方法。

一个有点相关的问题,你如何使用matplotlib 来绘制单个轴(例如,没有数据,只有轴)?例如,这可能有助于制作列线图。在我的用例中,如果我不能直接绘制圆形对数刻度,我也许可以将线性对数刻度后处理成圆形——也许。

Here is an old circular slide rule 为例。我想做 C 或 D(360 度一个完整的对数循环)、A(两个循环)和 K(三个循环)等刻度。

【问题讨论】:

  • 你可以链接到你提到的例子吗?是这个吗? stackoverflow.com/questions/36919275/…
  • 如果你关注我上面提到的问题,线性来自np.linspace(0, 2pi, 24) in ax.set_xticks()。如果你想要某种对数缩放,你应该选择一些对数映射,将你的刻度点映射在 0 和 2pi 之间,而不是 np.linspace
  • This 是我看到的例子。但类似的概念。

标签: matplotlib circular-dependency logarithm polar-coordinates


【解决方案1】:

试试这个

import numpy as np
import matplotlib.pyplot as plt     

ax = plt.subplot(111, polar=True)


lim_min = 1             # ln(1) = 0
lim_max = np.e**(2*np.pi)  # ln(e**(2*pi)) = 2*pi (np.log = ln)
N_LABLES = 24
XTICKS = [np.log(x) for x in np.linspace(lim_min, lim_max, N_LABLES, endpoint=False)]

# Set the circumference labels
ax.set_xticks(XTICKS)
ax.set_xticklabels(range(N_LABLES))

# Make the labels go clockwise
ax.set_theta_direction(-1)

# Place 0 at the top
ax.set_theta_offset(np.pi/2.0)       

plt.show()

您可以使用从 0 到 2pi 的精确缩放来获得您想要的情节。图制作:

【讨论】:

  • 这似乎是我的应用程序要走的路。我一直想使用 LogFormatter,就像我使用线性对数轴一样,但最后我认为它不合适。 matplotlib 原生的刻度线只有两级,但要绘制计算尺刻度,您需要 3 或 4 级。这种方法让我可以做到这一点,尽管有点乏味。我将在下面发布我对您的代码的修改,该代码绘制了一个对数刻度的周期。谢谢@ljbkusters
【解决方案2】:

根据@ljbkusters 的回答,我制作了一个单周期、循环的 log-base-10 比例。这将作为最终计算尺图稿更详细绘图的基础。

import numpy as np
import matplotlib.pyplot as plt     

ax = plt.subplot(111, polar=True)

# Make the labels go clockwise
ax.set_theta_direction(-1)
# Place 0 at the top
ax.set_theta_offset(np.pi/2.0)       

# Polar plots don't have tick marks, 
# cannot draw outside the max radius set by ylim
# Remove the frame, and y-axis,
# * draw our own axis circle
# * draw our own tick marks (below)
ax.set_ylim(0,100)
ax.grid(False)
ax.set_frame_on(False)
ax.axes.get_yaxis().set_visible(False)
angles = np.linspace(0.0, 2.0*np.pi, 100)
ax.plot( angles, 100*[95], color='black', lw=1.2 )

# Major
lim_min = 1 
lim_max = 10 
N_LABLES = 10
XTICKS = [2.0 * np.pi * np.log10(x) for x in np.linspace(lim_min, lim_max, N_LABLES-1, endpoint=False)]
ax.set_xticks(XTICKS)
# Set the circumference labels
ax.set_xticklabels(range(1, N_LABLES))
# Draw major tick marks
tick = [93,100]
for t in XTICKS:
    ax.plot([t,t], tick, lw=1.0, color='black')

# Minor
lim_min = 1 
lim_max = 10 
N_LABLES = 100
XTICKS = [2.0 * np.pi * np.log10(x) for x in np.linspace(lim_min, lim_max, N_LABLES-1, endpoint=False)]
ax.set_xticks(XTICKS)
# Draw minor tick marks
tick = [95,98]
for t in XTICKS:
    ax.plot([t,t], tick, lw=0.5, color='blue')

plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 2019-08-25
    • 2017-08-22
    • 2014-05-15
    • 1970-01-01
    • 2017-05-18
    相关资源
    最近更新 更多