2013-05-17 160 views
7

我在想,是否有可能偏移径向轴的起点或将它移到图的外部。Matplotlib极坐标图径向轴偏移量

这就是我希望能实现:

Goal

这就是我现在。

CurRes

我已经阅读SO文档和不同的主题,但我无法找到任何有用的。这是否意味着如果在任何地方都没有提到它是不可能的。

预先感谢您。

EDIT(用于创建绘图代码添加片段):

ax = fig.add_subplot(111, projection='polar') 
ax.set_theta_zero_location('N') 
ax.set_theta_direction(-1)  
ax.plot(X,lines[li]*yScalingFactor,label=linelabels[li],color=color,linestyle=ls) 
+0

请发布您的代码,生成该图。 –

+0

代码是极坐标绘图的标准,但我仍然编辑帖子并添加了代码。 而数据不是来自公式,而是来自一组数据。 – Renesis

回答

6

我不知道,如果polar plot可以这样进行调整。但是,这是一个解决方法,基于the last example given here: Floating Axes

我已经包含在代码中解释性意见,如果你复制/粘贴,它应该运行的-是:

import mpl_toolkits.axisartist.floating_axes as floating_axes 
from matplotlib.projections import PolarAxes 
from mpl_toolkits.axisartist.grid_finder import FixedLocator, \ 
    MaxNLocator, DictFormatter 
import numpy as np 
import matplotlib.pyplot as plt 

# generate 100 random data points 
# order the theta coordinates 

# theta between 0 and 2*pi 
theta = np.random.rand(100)*2.*np.pi 
theta = np.sort(theta) 

# "radius" between 0 and a max value of 40,000 
# as roughly in your example 
# normalize the r coordinates and offset by 1 (will be clear later) 
MAX_R = 40000. 
radius = np.random.rand(100)*MAX_R 
radius = radius/np.max(radius) + 1. 

# initialize figure: 
fig = plt.figure() 

# set up polar axis 
tr = PolarAxes.PolarTransform() 

# define angle ticks around the circumference: 
angle_ticks = [(0, r"$0$"), 
       (.25*np.pi, r"$\frac{1}{4}\pi$"), 
       (.5*np.pi, r"$\frac{1}{2}\pi$"), 
       (.75*np.pi, r"$\frac{3}{4}\pi$"), 
       (1.*np.pi, r"$\pi$"), 
       (1.25*np.pi, r"$\frac{5}{4}\pi$"), 
       (1.5*np.pi, r"$\frac{3}{2}\pi$"), 
       (1.75*np.pi, r"$\frac{7}{4}\pi$")] 

# set up ticks and spacing around the circle 
grid_locator1 = FixedLocator([v for v, s in angle_ticks]) 
tick_formatter1 = DictFormatter(dict(angle_ticks)) 

# set up grid spacing along the 'radius' 
radius_ticks = [(1., '0.0'), 
       (1.5, '%i' % (MAX_R/2.)), 
       (2.0, '%i' % (MAX_R))] 

grid_locator2 = FixedLocator([v for v, s in radius_ticks]) 
tick_formatter2 = DictFormatter(dict(radius_ticks)) 

# set up axis: 
# tr: the polar axis setup 
# extremes: theta max, theta min, r max, r min 
# the grid for the theta axis 
# the grid for the r axis 
# the tick formatting for the theta axis 
# the tick formatting for the r axis 
grid_helper = floating_axes.GridHelperCurveLinear(tr, 
                extremes=(2.*np.pi, 0, 2, 1), 
                grid_locator1=grid_locator1, 
                grid_locator2=grid_locator2, 
                tick_formatter1=tick_formatter1, 
                tick_formatter2=tick_formatter2) 

ax1 = floating_axes.FloatingSubplot(fig, 111, grid_helper=grid_helper) 
fig.add_subplot(ax1) 

# create a parasite axes whose transData in RA, cz 
aux_ax = ax1.get_aux_axes(tr) 

aux_ax.patch = ax1.patch # for aux_ax to have a clip path as in ax 
ax1.patch.zorder=0.9 # but this has a side effect that the patch is 
        # drawn twice, and possibly over some other 
        # artists. So, we decrease the zorder a bit to 
        # prevent this. 

# plot your data: 
aux_ax.plot(theta, radius) 
plt.show() 

,这将产生以下情节:

pseudo polar plot

您必须调整轴标签以满足您的要求。
我缩放了数据,因为否则就会出现与您的情节相同的问题 - 内部空圆会缩放为点。您可以尝试使用极坐标图进行缩放,并将自定义标签放在径向轴上以获得类似的效果。

+0

我一段时间都没有活跃,我没想到有人会真的帮忙。 这有点帮助,我希望我能够修改它,以便它是需要的。 – Renesis

+0

我想我会在星期一尝试修改这个,然后我会报告结果。 再次感谢您。 – Renesis