2012-11-14 8 views
3

두 개의 y 축 (즉, 두 개의 다른 S.I. 축척)을 단일 x 축과 관련된 그림을 그립니다. 몇 가지 값을 확대해야하고 Matplotlib의 zoom_inset_locator 트릭을 사용하여이 값을 관리합니다. 나는 줌 축를 달성하지만 두 번째 y 축 (아래 예 참조) 실종 :삽입 된 줌 축에 두 번째 Y 축 추가

Two-y axis and an inset zoom

그것은 다시) (twinx를 사용하여 두 번째 축을 추가하려고 않았다,하지만 그것은 음모로 실패 축 주요 twinx에 (오른쪽) 축하지만 줌 우측 축에 빈 진드기를 떠나이 x 축에게 적절한 치료를 제공하는 것, 아래 참조 : 어떤 해결 방법은

enter image description here

있습니까?

import numpy,os,sys 
import pylab 
import scipy.optimize 
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes 
from mpl_toolkits.axes_grid1.inset_locator import mark_inset 

# Initializing the curve 
fig_cal=pylab.figure() 
host_weight = fig_cal.add_subplot(111) 
host_mass = host_weight.twinx() 
Tension = numpy.linspace(0,0.08,100) 
Weight = 0.5* Tension 
Mass = Weight/9.81 

# Plotting the curve 

host_weight.plot(Tension, Weight, 'r', label='Fitted line',lw=2) 
host_mass.plot(Tension, Mass) 

# Cosmetic on the Figure 
host_weight.set_xlabel("Tension U [$V$]") 
host_weight.set_ylabel("Weight F [$N$]") 
host_mass.set_ylabel("Mass M [$kg$]") 
host_mass.set_ylim(host_weight.axis()[-2]/9.81, host_weight.axis()[-1]/9.81) 
host_weight.grid(False) 

# Zoom on the first measurement 
zoom_weight = zoomed_inset_axes(host_weight, zoom = 7.5, bbox_to_anchor=(0.95,0.5), bbox_transform=host_weight.transAxes) 
zoom_weight.plot(Tension[:4], Weight[:4], 'r', lw=2) 
zoom_weight.set_xticks(zoom_weight.xaxis.get_majorticklocs()[::2]) 
zoom_weight.set_yticks(zoom_weight.yaxis.get_majorticklocs()[::2]) 
# zoom_mass = zoom_weight.twinx() 

# zoom_mass.plot(Tension[:4], Mass[:4],alpha=0) 
# zoom_mass.set_ylim(zoom_weight.axis()[-2]/9.81,zoom_weight.axis()[-1]/9.81) 
mark_inset(host_weight, zoom_weight, loc1=2, loc2=4, fc="none", ec="0.5") 

pylab.show() 
+1

그것은 단지 가장 이상합니다. 그것은 * axes_grid1 툴킷의 ​​버그 인 것 같습니다. –

+0

+1이 멋진 'zoomed_inset_axes'기능을 보여주었습니다. –

+0

나는 당신이 [github] (https://github.com/matplotlib/matplotlib/issues/1499) – TazgerO

답변

0

그래서 내 질문에 대한 답을 찾았습니다 ... 지연에 대해 유감스럽게 생각했지만,이 문제를 보류했습니다.

import numpy,os,sys 
import pylab 
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes 
from mpl_toolkits.axes_grid1.inset_locator import mark_inset 

# Initializing the curve 
fig_cal=pylab.figure() 
host_weight = fig_cal.add_subplot(111) 
host_mass = host_weight.twinx() 
Tension = numpy.linspace(0,0.08,100) 
Weight = 0.5* Tension 
Mass = Weight/9.81 

# Plotting the curve 
host_weight.plot(Tension, Weight, 'r', label='Fitted line',lw=2) 
host_mass.plot(Tension, Mass, alpha=0) 

# Cosmetic on the Figure 
host_weight.set_xlabel("Tension U [$V$]") 
host_weight.set_ylabel("Weight F [$N$]") 
host_mass.set_ylabel("Mass M [$kg$]") 
host_mass.set_ylim(host_weight.axis()[-2]/9.81, host_weight.axis()[-1]/9.81) 
host_weight.grid(False) 

# Zoom on the first measurement 
zoom_weight = zoomed_inset_axes(host_weight, zoom = 7.5, bbox_to_anchor=(0.95,0.5), bbox_transform=host_weight.transAxes) 
zoom_weight.plot(Tension[:4], Weight[:4], 'r', lw=2) 
zoom_weight.set_xticks(zoom_weight.xaxis.get_majorticklocs()[::2]) 
zoom_weight.set_yticks(zoom_weight.yaxis.get_majorticklocs()[::2]) 
zoom_mass = zoomed_inset_axes(host_mass, zoom = 7.5, bbox_to_anchor=(0.95,0.5),  bbox_transform=host_mass.transAxes) 
zoom_mass.xaxis.set_visible(False) 
zoom_mass.spines['left'].set_visible(False) 
zoom_mass.spines['top'].set_visible(False) 
zoom_mass.patch.set_alpha(00) 
zoom_mass.yaxis.tick_right() 
zoom_mass.yaxis.set_label_position('right') 
zoom_mass.yaxis.set_offset_position('right') 
zoom_mass.plot(Tension[:4], Mass[:4],color='w', alpha=0) 
zoom_mass.set_ylim(zoom_weight.axis()[-2]/9.81,zoom_weight.axis()[-1]/9.81) 

pylab.show() 

어쩌면 가장 좋은 방법,하지만, 다음은

내 코드는 ... 버그하지만, 다른 줌 인 세트를 생성하는 알파 운하를 사용하여 물건을 많이 사용하지 않도록하여 단지 해결 방법을 찾을 수 그것은 작동합니다!

0

당신은 시세 포매터를 사용하는 것이 좋습니다 : 여기에 내가 그림을 그리는 데 사용되는 코드는

formatter = matplotlib.ticker.EngFormatter(unit='S', places=3) 
formatter.ENG_PREFIXES[-6] = 'u' 
plt.axes().yaxis.set_major_formatter(formatter) 

이 게시물에서보세요 :

코드는 다음과 같은 것입니다 그 음모가 어떻게 생길지에 대해 : matplotlib; fractional powers of ten; scientific notation

+0

에 직접 문제를 제기하는 것을 보았다. 그것은 참으로 멋진 특징이다 !! 나는 그것을 염두에 두겠다. – TazgerO