Matplotlib:使用对数 Angular 轴制作极坐标图

Matplotlib: Making Polar Plot with Logarithmic Angular Axis

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

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

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

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

试试这个

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 的精确比例来按照您想要的方式绘制绘图。图制作:

根据@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()