2013-05-17 6 views
7

Zastanawiam się, czy możliwe jest przesunięcie początku osi promieniowej lub przesunięcie jej poza wykresem.Plansza biegunowa Matplotlib przesunięcie osiowe

To, co mam nadzieję osiągnąć:

Goal

I to jest to, co mam teraz.

CurRes

Czytałem dokumentację i różne tematy na SO, ale nie mogłem znaleźć niczego przydatne. Czy to oznacza, że ​​nie jest to możliwe, jeśli nigdzie się o tym nie wspomina.

Z góry dziękuję.

EDIT (dodany fragment kodu użytego do stworzenia fabuły):

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

Proszę zaksięgować swój kod, który wygenerował diagram. –

+0

Kod jest standardowym wykresem polarnym, ale mimo to zredagowałem wpis i dodałem kod. Dane nie pochodzą z formuły, ale z zestawu danych. – Renesis

Odpowiedz

6

Nie jestem pewien, czy polar plot można regulować tak. Ale tutaj jest obejście, oparte na the last example given here: Floating Axes.

mam włączone komentarze wyjaśniające w kodzie, jeśli skopiować/wkleić go, powinien działać jak jest:

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() 

To będzie generować następujące działki:

pseudo polar plot

Musisz dostosować etykiety osi, aby spełnić Twoje wymagania.
Przeskalowałem dane, ponieważ w przeciwnym razie wystąpiłby ten sam problem, co w przypadku wykresu - wewnętrzne, puste koło zostałoby przeskalowane do kropki. Możesz spróbować skalowania za pomocą wykresu biegunowego i po prostu umieścić niestandardowe etykiety na osi promieniowej, aby osiągnąć podobny efekt.

+0

Nie byłem od jakiegoś czasu aktywny i nie spodziewałem się, że ktoś naprawdę pomoże. To trochę pomaga i mam nadzieję, że będę mógł go zmodyfikować tak, jak jest potrzebny. – Renesis

+0

Myślę, że postaram się to zmienić w poniedziałek, wtedy zgłoś wyniki. Jeszcze raz dziękuję. – Renesis