두 개의 y 축 (즉, 두 개의 다른 S.I. 축척)을 단일 x 축과 관련된 그림을 그립니다. 몇 가지 값을 확대해야하고 Matplotlib의 zoom_inset_locator 트릭을 사용하여이 값을 관리합니다. 나는 줌 축를 달성하지만 두 번째 y 축 (아래 예 참조) 실종 :삽입 된 줌 축에 두 번째 Y 축 추가
그것은 다시) (twinx를 사용하여 두 번째 축을 추가하려고 않았다,하지만 그것은 음모로 실패 축 주요 twinx에 (오른쪽) 축하지만 줌 우측 축에 빈 진드기를 떠나이 x 축에게 적절한 치료를 제공하는 것, 아래 참조 : 어떤 해결 방법은
있습니까?
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()
그것은 단지 가장 이상합니다. 그것은 * axes_grid1 툴킷의 버그 인 것 같습니다. –
+1이 멋진 'zoomed_inset_axes'기능을 보여주었습니다. –
나는 당신이 [github] (https://github.com/matplotlib/matplotlib/issues/1499) – TazgerO