3

2つのy軸(つまり、2つの異なるSIスケール)を1つのx軸に関連付ける図を描きます。いくつかの値を拡大する必要があり、Matplotlibのzoom_inset_locatorトリックを使用して管理します。ズーム軸を達成しましたが、2番目のy軸がありません(以下の例を参照)。

2y軸とはめ込みズーム

twinx()を使用して2番目の軸を再度追加しようとしましたが、軸をメインの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()
4

2 に答える 2

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

最善の方法ではないかもしれませんが、うまくいきます!!!

于 2013-01-18T21:27:18.533 に答える
0

ティッカーフォーマッターの使用を検討してください。

コードは次のようなものです。

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

プロットがどのようになるかについては、この投稿を ご覧ください。10 の分数べき乗; 科学表記法

于 2012-11-15T00:02:35.723 に答える