|
| 1 | +from __future__ import (absolute_import, division, print_function, |
| 2 | + unicode_literals) |
| 3 | + |
| 4 | +import six |
| 5 | + |
| 6 | +import numpy as np |
| 7 | + |
| 8 | +import matplotlib.pyplot as plt |
| 9 | +import matplotlib.projections as mprojections |
| 10 | +import matplotlib.transforms as mtransforms |
| 11 | +from matplotlib.testing.decorators import cleanup, image_comparison |
| 12 | +from mpl_toolkits.axes_grid.axislines import Subplot |
| 13 | +from mpl_toolkits.axisartist.floating_axes import ( |
| 14 | + ExtremeFinderFixed, |
| 15 | + FixedAxisArtistHelper, |
| 16 | + FloatingAxesBase, |
| 17 | + FloatingAxisArtistHelper, |
| 18 | + FloatingSubplot, |
| 19 | + GridHelperCurveLinear, |
| 20 | + floatingaxes_class_factory) |
| 21 | +from mpl_toolkits.axisartist.grid_finder import ( |
| 22 | + ExtremeFinderSimple, |
| 23 | + FixedLocator) |
| 24 | +from mpl_toolkits.axisartist import angle_helper |
| 25 | + |
| 26 | + |
| 27 | +@cleanup |
| 28 | +def test_subplot(): |
| 29 | + fig = plt.figure(figsize=(5, 5)) |
| 30 | + fig.clf() |
| 31 | + |
| 32 | + ax = Subplot(fig, 111) |
| 33 | + fig.add_subplot(ax) |
| 34 | + |
| 35 | + |
| 36 | +@image_comparison(baseline_images=['curvelinear3'], |
| 37 | + extensions=['png'], style='default', tol=0.01) |
| 38 | +def test_curvelinear3(): |
| 39 | + fig = plt.figure(figsize=(5, 5)) |
| 40 | + fig.clf() |
| 41 | + |
| 42 | + tr = (mtransforms.Affine2D().scale(np.pi / 180.0, 1.0) + |
| 43 | + mprojections.PolarAxes.PolarTransform()) |
| 44 | + |
| 45 | + grid_locator1 = angle_helper.LocatorDMS(15) |
| 46 | + tick_formatter1 = angle_helper.FormatterDMS() |
| 47 | + |
| 48 | + grid_locator2 = FixedLocator([2, 4, 6, 8, 10]) |
| 49 | + |
| 50 | + grid_helper = GridHelperCurveLinear(tr, |
| 51 | + extremes=(0, 360, 10, 3), |
| 52 | + grid_locator1=grid_locator1, |
| 53 | + grid_locator2=grid_locator2, |
| 54 | + tick_formatter1=tick_formatter1, |
| 55 | + tick_formatter2=None) |
| 56 | + |
| 57 | + ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper) |
| 58 | + fig.add_subplot(ax1) |
| 59 | + |
| 60 | + r_scale = 10.0 |
| 61 | + tr2 = mtransforms.Affine2D().scale(1.0, 1.0 / r_scale) + tr |
| 62 | + grid_locator2 = FixedLocator([30, 60, 90]) |
| 63 | + grid_helper2 = GridHelperCurveLinear(tr2, |
| 64 | + extremes=(0, 360, |
| 65 | + 10 * r_scale, 3 * r_scale), |
| 66 | + grid_locator2=grid_locator2) |
| 67 | + |
| 68 | + ax1.axis["right"] = axis = grid_helper2.new_fixed_axis("right", axes=ax1) |
| 69 | + |
| 70 | + ax1.axis["left"].label.set_text("Test 1") |
| 71 | + ax1.axis["right"].label.set_text("Test 2") |
| 72 | + |
| 73 | + for an in ["left", "right"]: |
| 74 | + ax1.axis[an].set_visible(False) |
| 75 | + |
| 76 | + axis = grid_helper.new_floating_axis(1, 7, axes=ax1, |
| 77 | + axis_direction="bottom") |
| 78 | + ax1.axis["z"] = axis |
| 79 | + axis.toggle(all=True, label=True) |
| 80 | + axis.label.set_text("z = ?") |
| 81 | + axis.label.set_visible(True) |
| 82 | + axis.line.set_color("0.5") |
| 83 | + |
| 84 | + ax2 = ax1.get_aux_axes(tr) |
| 85 | + |
| 86 | + xx, yy = [67, 90, 75, 30], [2, 5, 8, 4] |
| 87 | + ax2.scatter(xx, yy) |
| 88 | + l, = ax2.plot(xx, yy, "k-") |
| 89 | + l.set_clip_path(ax1.patch) |
| 90 | + |
| 91 | + |
| 92 | +@image_comparison(baseline_images=['curvelinear4'], |
| 93 | + extensions=['png'], style='default', tol=0.01) |
| 94 | +def test_curvelinear4(): |
| 95 | + fig = plt.figure(figsize=(5, 5)) |
| 96 | + fig.clf() |
| 97 | + |
| 98 | + tr = (mtransforms.Affine2D().scale(np.pi / 180.0, 1.0) + |
| 99 | + mprojections.PolarAxes.PolarTransform()) |
| 100 | + |
| 101 | + grid_locator1 = angle_helper.LocatorDMS(5) |
| 102 | + tick_formatter1 = angle_helper.FormatterDMS() |
| 103 | + |
| 104 | + grid_locator2 = FixedLocator([2, 4, 6, 8, 10]) |
| 105 | + |
| 106 | + grid_helper = GridHelperCurveLinear(tr, |
| 107 | + extremes=(120, 30, 10, 0), |
| 108 | + grid_locator1=grid_locator1, |
| 109 | + grid_locator2=grid_locator2, |
| 110 | + tick_formatter1=tick_formatter1, |
| 111 | + tick_formatter2=None) |
| 112 | + |
| 113 | + ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper) |
| 114 | + fig.add_subplot(ax1) |
| 115 | + |
| 116 | + ax1.axis["left"].label.set_text("Test 1") |
| 117 | + ax1.axis["right"].label.set_text("Test 2") |
| 118 | + |
| 119 | + for an in ["top"]: |
| 120 | + ax1.axis[an].set_visible(False) |
| 121 | + |
| 122 | + axis = grid_helper.new_floating_axis(1, 70, axes=ax1, |
| 123 | + axis_direction="bottom") |
| 124 | + ax1.axis["z"] = axis |
| 125 | + axis.toggle(all=True, label=True) |
| 126 | + axis.label.set_axis_direction("top") |
| 127 | + axis.label.set_text("z = ?") |
| 128 | + axis.label.set_visible(True) |
| 129 | + axis.line.set_color("0.5") |
| 130 | + |
| 131 | + ax2 = ax1.get_aux_axes(tr) |
| 132 | + |
| 133 | + xx, yy = [67, 90, 75, 30], [2, 5, 8, 4] |
| 134 | + ax2.scatter(xx, yy) |
| 135 | + l, = ax2.plot(xx, yy, "k-") |
| 136 | + l.set_clip_path(ax1.patch) |
0 commit comments