def test_clipping_of_log(): # issue 804 M, L, C = Path.MOVETO, Path.LINETO, Path.CLOSEPOLY points = [(0.2, -99), (0.4, -99), (0.4, 20), (0.2, 20), (0.2, -99)] codes = [M, L, L, L, C] path = Path(points, codes) # something like this happens in plotting logarithmic histograms trans = mtransforms.BlendedGenericTransform(mtransforms.Affine2D(), scale.LogTransform(10, 'clip')) tpath = trans.transform_path_non_affine(path) result = tpath.iter_segments(trans.get_affine(), clip=(0, 0, 100, 100), simplify=False) tpoints, tcodes = zip(*result) assert_allclose(tcodes, [M, L, L, L, C])
def sketch_model(mod, axes=None, shade=True): from matplotlib import transforms axes = getaxes(axes) trans = transforms.BlendedGenericTransform(axes.transAxes, axes.transData) for dis in mod.discontinuities(): color = shades[-1] axes.axhline(dis.z, color=dark(color), lw=1.5) if dis.name is not None: axes.text(0.90, dis.z, dis.name, transform=trans, va='center', ha='right', color=dark(color), bbox=dict(ec=dark(color), fc=light(color, 0.3), pad=8, lw=1)) for ilay, lay in enumerate(mod.layers()): if isinstance(lay, cake.GradientLayer): tab = shades else: tab = shades2 color = tab[ilay % len(tab)] if shade: axes.axhspan(lay.ztop, lay.zbot, fc=color, ec=dark(color), label='abc') if lay.name is not None: axes.text(0.95, (lay.ztop + lay.zbot) * 0.5, lay.name, transform=trans, va='center', ha='right', color=dark(color), bbox=dict(ec=dark(color), fc=light(color, 0.3), pad=8, lw=1))
input_dims = 1 output_dims = 1 is_separable = False has_inverse = True def __init__(self): mtransforms.Transform.__init__(self) def transform_non_affine(self, wl): return (wl * un.k).to(un.micron, equivalencies=un.spectral()).value def inverted(self): return Micron2WNTransform() aux_trans = mtransforms.BlendedGenericTransform( Micron2WNTransform(), mtransforms.IdentityTransform()) fig = plt.figure(1) for n in range(1, 4, 1): ax_mn = SubplotHost(fig, 1, 3, n) fig.add_subplot(ax_mn) ax_mn.set_xlabel('Wavelength (micron)') # x_micron=np.array([15,10,5,3]) # ax_mn.set_xticks(x_micron) # ax_mn.set_xlim(5,15) ax_mn.set_ylim(0, 6) ax_mn.set_xscale('log') test_spectrum = np.genfromtxt('sample_spectrum.dpt', delimiter=',')
output_dims = 1 is_separable = False has_inverse = True def __init__(self): mtransforms.Transform.__init__(self) def transform_non_affine(self, wl): return (wl*un.micron).to(un.k, equivalencies=un.spectral()).value def inverted(self): return WN2MicronTransform() aux_trans = mtransforms.BlendedGenericTransform(WN2MicronTransform(), mtransforms.IdentityTransform()) fig = plt.figure(1) fig.set_size_inches(7,4) offset=0 ax_wn = SubplotHost(fig, 1, 1, 1) fig.add_subplot(ax_wn) ax_mn = ax_wn.twin(aux_trans) ax_mn.set_viewlim_mode("transform") # x_micron=np.array([12, 10, 8, 6]) # ax_mn.set_xticks(x_micron) ax_mn.xaxis.tick_bottom()