diff --git a/lib/mpl_toolkits/axisartist/angle_helper.py b/lib/mpl_toolkits/axisartist/angle_helper.py index 7f2b5d338b7c..4ca0a93fc81c 100644 --- a/lib/mpl_toolkits/axisartist/angle_helper.py +++ b/lib/mpl_toolkits/axisartist/angle_helper.py @@ -162,27 +162,22 @@ def select_step360(v1, v2, nv, include_last=True, threshold_factor=3600): threshold_factor=threshold_factor) - class LocatorBase(object): def __init__(self, den, include_last=True): self.den = den self._include_last = include_last - def _get_nbins(self): + @property + def nbins(self): return self.den - def _set_nbins(self, v): + @nbins.setter + def nbins(self, v): self.den = v - nbins = property(_get_nbins, _set_nbins) - - def set_params(self, **kwargs): - if "nbins" in kwargs: - self.den = int(kwargs.pop("nbins")) - - if kwargs: - raise ValueError("Following keys are not processed: %s" - % ", ".join(kwargs)) + def set_params(self, nbins=None): + if nbins is not None: + self.den = int(nbins) class LocatorHMS(LocatorBase): @@ -215,25 +210,21 @@ def __call__(self, v1, v2): threshold_factor=1) - class FormatterDMS(object): - deg_mark = "^{\circ}" min_mark = "^{\prime}" sec_mark = "^{\prime\prime}" - fmt_d = "$%d"+deg_mark+"$" - fmt_ds = r"$%d.\!\!"+deg_mark+"%s$" - - # %s for signe - fmt_d_m = r"$%s%d"+deg_mark+"\,%02d"+min_mark+"$" - fmt_d_ms = r"$%s%d"+deg_mark+"\,%02d.\mkern-4mu"+min_mark+"%s$" + fmt_d = "$%d" + deg_mark + "$" + fmt_ds = r"$%d.%s" + deg_mark + "$" + # %s for sign + fmt_d_m = r"$%s%d" + deg_mark + "\,%02d" + min_mark + "$" + fmt_d_ms = r"$%s%d" + deg_mark + "\,%02d.%s" + min_mark + "$" - fmt_d_m_partial = "$%s%d"+deg_mark+"\,%02d"+min_mark+"\," - fmt_s_partial = "%02d"+sec_mark+"$" - fmt_ss_partial = "%02d.\!\!"+sec_mark+"%s$" - + fmt_d_m_partial = "$%s%d" + deg_mark + "\,%02d" + min_mark + "\," + fmt_s_partial = "%02d" + sec_mark + "$" + fmt_ss_partial = "%02d.%s" + sec_mark + "$" def _get_number_fraction(self, factor): ## check for fractional numbers @@ -292,7 +283,7 @@ def __call__(self, direction, factor, values): if ss[-1] == -1: inverse_order = True values = values[::-1] - sings = signs[::-1] + signs = signs[::-1] else: inverse_order = False @@ -313,7 +304,7 @@ def __call__(self, direction, factor, values): l_hm_old = l_hm l = l_hm + s1 #l_s else: - l = "$"+s1 #l_s + l = "$" + s + s1 r.append(l) if inverse_order: @@ -324,23 +315,22 @@ def __call__(self, direction, factor, values): else: # factor > 3600. return [r"$%s^{\circ}$" % (str(v),) for v in ss*values] + class FormatterHMS(FormatterDMS): deg_mark = "^\mathrm{h}" min_mark = "^\mathrm{m}" sec_mark = "^\mathrm{s}" - fmt_d = "$%d"+deg_mark+"$" - fmt_ds = r"$%d.\!\!"+deg_mark+"%s$" - - # %s for signe - fmt_d_m = r"$%s%d"+deg_mark+"\,%02d"+min_mark+"$" - fmt_d_ms = r"$%s%d"+deg_mark+"\,%02d.\!\!"+min_mark+"%s$" + fmt_d = "$%d" + deg_mark + "$" + fmt_ds = r"$%d.%s" + deg_mark + "$" + # %s for sign + fmt_d_m = r"$%s%d" + deg_mark + "\,%02d" + min_mark+"$" + fmt_d_ms = r"$%s%d" + deg_mark + "\,%02d.%s" + min_mark+"$" - fmt_d_m_partial = "$%s%d"+deg_mark+"\,%02d"+min_mark+"\," - fmt_s_partial = "%02d"+sec_mark+"$" - fmt_ss_partial = "%02d.\!\!"+sec_mark+"%s$" - + fmt_d_m_partial = "$%s%d" + deg_mark + "\,%02d" + min_mark + "\," + fmt_s_partial = "%02d" + sec_mark + "$" + fmt_ss_partial = "%02d.%s" + sec_mark + "$" def __call__(self, direction, factor, values): # hour return FormatterDMS.__call__(self, direction, factor, np.asarray(values)/15.) @@ -426,50 +416,3 @@ def _adjust_extremes(self, lon_min, lon_max, lat_min, lat_max): lat_max = min(max0, lat_max) return lon_min, lon_max, lat_min, lat_max - - - - - -if __name__ == "__main__": - #test2() - #print select_step360(21.2, 33.3, 5) - #print select_step360(20+21.2/60., 21+33.3/60., 5) - #print select_step360(20.5+21.2/3600., 20.5+33.3/3600., 5) - - # test threshold factor - print(select_step360(20.5+11.2/3600., 20.5+53.3/3600., 5, - threshold_factor=60)) - - print(select_step360(20.5+11.2/3600., 20.5+53.3/3600., 5, - threshold_factor=1)) - - fmt = FormatterDMS() - #print fmt("left", 60, [0, -30, -60]) - print(fmt("left", 600, [12301, 12302, 12303])) - - print(select_step360(20.5+21.2/3600., 20.5+21.4/3600., 5)) - print(fmt("left", 36000, [738210, 738215, 738220])) - print(fmt("left", 360000, [7382120, 7382125, 7382130])) - print(fmt("left", 1., [45, 46, 47])) - print(fmt("left", 10., [452, 453, 454])) - -if 0: - print(select_step360(20+21.2/60., 21+33.3/60., 5)) - print(select_step360(20.5+21.2/3600., 20.5+33.3/3600., 5)) - print(select_step360(20+21.2/60., 20+53.3/60., 5)) - - ### - levs, n, factor = select_step360(20.5+21.2/3600., 20.5+27.25/3600., 5) - levs = levs * 0.1 - fmt = FormatterDMS() - #print fmt("left", 60, [0, -30, -60]) - print(fmt("left", factor, levs)) - - - print(select_step(-180, 180, 10, hour=False)) - print(select_step(-12, 12, 10, hour=True)) - - fmt = FormatterDMS() - #print fmt("left", 60, [0, -30, -60]) - print(fmt("left", 3600, [0, -30, -60])) diff --git a/lib/mpl_toolkits/axisartist/axis_artist.py b/lib/mpl_toolkits/axisartist/axis_artist.py index edab52f218b9..5e850330dd82 100644 --- a/lib/mpl_toolkits/axisartist/axis_artist.py +++ b/lib/mpl_toolkits/axisartist/axis_artist.py @@ -310,7 +310,6 @@ def draw(self, renderer): gc = renderer.new_gc() - self._set_gc_clip(gc) gc.set_foreground(self.get_markeredgecolor()) gc.set_linewidth(self.get_markeredgewidth()) gc.set_alpha(self._alpha) @@ -327,32 +326,17 @@ def draw(self, renderer): marker_transform = marker_scale + marker_rotation for loc, angle in self.locs_angles: - marker_rotation.rotate_deg(angle+add_angle) - locs = path_trans.transform_non_affine(np.array([loc, loc])) + marker_rotation.clear().rotate_deg(angle+add_angle) + locs = path_trans.transform_non_affine([loc]) + if (self.axes and + not self.axes.viewLim.contains(locs[0][0], locs[0][1])): + continue renderer.draw_markers(gc, self._tickvert_path, marker_transform, Path(locs), path_trans.get_affine()) - marker_rotation.clear() gc.restore() -def test_ticks(): - import matplotlib.pyplot as plt - fig = plt.figure(1) - fig.clf() - ax = fig.add_subplot(111) - ax.xaxis.set_visible(False) - ax.yaxis.set_visible(False) - ticks = Ticks(ticksize=10, axis=ax.xaxis) - ax.add_artist(ticks) - locs_angles = [((0.2, 0.), 90), - ((0.4, 0.), 120)] - ticks.set_locs_angles(locs_angles) - plt.draw() - - - - class LabelBase(mtext.Text): """ A base class for AxisLabel and TickLabels. The position and angle @@ -464,33 +448,6 @@ def get_window_extent(self, renderer): return bbox - -def test_labelbase(): - import matplotlib.pyplot as plt - fig = plt.figure(1) - fig.clf() - ax = fig.add_subplot(111) - - ax.plot([0.5], [0.5], "o") - label = LabelBase(0.5, 0.5, "Test") - - a = -90 - label._set_ref_angle(a) - label._set_offset_radius(offset_radius=50) - label.set_rotation(-90) - label.set(ha="center", va="top") - - ax.add_artist(label) - plt.draw() - - - - - - - - - class AxisLabel(LabelBase, AttributeCopier): """ Axis Label. Derived from Text. The position of the text is updated @@ -846,47 +803,6 @@ def get_texts_widths_heights_descents(self, renderer): return whd_list - -def test_ticklabels(): - import matplotlib.pyplot as plt - fig = plt.figure(1) - fig.clf() - ax = fig.add_subplot(111) - ax.xaxis.set_visible(False) - ax.yaxis.set_visible(False) - ax.plot([0.2, 0.4], [0.5, 0.5], "o") - ticks = Ticks(ticksize=10, axis=ax.xaxis) - ax.add_artist(ticks) - locs_angles_labels = [((0.2, 0.5), -90, "0.2"), - ((0.4, 0.5), -120, "0.4")] - tick_locs_angles = [(xy, a+180) for xy, a, l in locs_angles_labels] - ticks.set_locs_angles(tick_locs_angles) - - - ax.plot([0.5], [0.5], ",") - axislabel = AxisLabel(0.5, 0.5, "Test") - axislabel._set_offset_radius(20) - axislabel._set_ref_angle(0) - axislabel.set_axis_direction("bottom") - #axislabel._text_follow_ref_angle = True - #axislabel.set(va="center", ha="right") - ax.add_artist(axislabel) - - if 1: - ticklabels = TickLabels(axis_direction="left") - ticklabels._locs_angles_labels = locs_angles_labels - #ticklabels.set_rotation(90) - ticklabels.set_pad(10) - - ax.add_artist(ticklabels) - - ax.set_xlim(0, 1); ax.set_ylim(0, 1) - - plt.draw() - - - - class GridlinesCollection(LineCollection): def __init__(self, *kl, **kwargs): """ @@ -928,14 +844,13 @@ class AxisArtist(martist.Artist): ZORDER=2.5 - # LABELPAD : as property - def _set_labelpad(self, v): - return self.label.set_pad(v) - - def _get_labelpad(self): + @property + def LABELPAD(self): return self.label.get_pad() - LABELPAD = property(_get_labelpad, _set_labelpad) + @LABELPAD.setter + def LABELPAD(self, v): + return self.label.set_pad(v) def __init__(self, axes, helper, @@ -1611,81 +1526,3 @@ def toggle(self, all=None, ticks=None, ticklabels=None, label=None): self.minor_ticklabels.set_visible(_ticklabels) if _label is not None: self.label.set_visible(_label) - - - - - -def test_axis_artist(): - global axisline - - #self._axislines[loc] = new_fixed_axis(loc=loc, axes=axes) - from mpl_toolkits.axisartist import AxisArtistHelperRectlinear - fig = plt.figure(1) - fig.clf() - ax=fig.add_subplot(111) - ax.xaxis.set_visible(False) - ax.yaxis.set_visible(False) - - if 1: - - _helper = AxisArtistHelperRectlinear.Fixed(ax, loc="left") - axisline = AxisArtist(ax, _helper, offset=None, axis_direction="left") - ax.add_artist(axisline) - _helper = AxisArtistHelperRectlinear.Fixed(ax, loc="right") - axisline = AxisArtist(ax, _helper, offset=None, axis_direction="right") - ax.add_artist(axisline) - - _helper = AxisArtistHelperRectlinear.Fixed(ax, loc="bottom") - axisline = AxisArtist(ax, _helper, offset=None, axis_direction="bottom") - axisline.set_label("TTT") - #axisline.label.set_visible(False) - ax.add_artist(axisline) - - #axisline.major_ticklabels.set_axis_direction("bottom") - axisline.major_ticks.set_tick_out(False) - - ax.set_ylabel("Test") - - axisline.label.set_pad(5) - - - plt.draw() - -def test_axis_artist2(): - global axisline - - #self._axislines[loc] = new_fixed_axis(loc=loc, axes=axes) - from mpl_toolkits.axislines import AxisArtistHelperRectlinear - fig = plt.figure(1) - fig.clf() - ax=fig.add_subplot(111) - ax.xaxis.set_visible(False) - ax.yaxis.set_visible(False) - - - _helper = AxisArtistHelperRectlinear.Fixed(ax, loc="bottom") - axisline = AxisArtist(ax, _helper, offset=None, axis_direction="bottom") - axisline.set_label("TTT") - ax.add_artist(axisline) - - #axisline.major_ticklabels.set_axis_direction("bottom") - axisline.major_ticks.set_tick_out(False) - - - ax.set_ylabel("Test") - - plt.draw() - -if __name__ == "__main__": - #test_labelbase() - #test_ticklabels() - test_axis_artist() - #test_axis_artist2() - - -# DONE -# *. ticks, ticklabels, axislabels -# *. workon axisartist - -# TODO diff --git a/lib/mpl_toolkits/axisartist/axislines.py b/lib/mpl_toolkits/axisartist/axislines.py index ce74f05f735a..6182608cc5ba 100644 --- a/lib/mpl_toolkits/axisartist/axislines.py +++ b/lib/mpl_toolkits/axisartist/axislines.py @@ -641,11 +641,10 @@ def _init_axis_artists(self, axes=None): axisline.major_ticklabels.set_visible(False) axisline.minor_ticklabels.set_visible(False) - def _get_axislines(self): + @property + def axis(self): return self._axislines - axis = property(_get_axislines) - def new_gridlines(self, grid_helper=None): """ Create and return a new GridlineCollection instance. @@ -827,48 +826,3 @@ def _init_axis_artists(self): self._axislines["yzero"] = yaxis_zero SubplotZero = maxes.subplot_class_factory(AxesZero) - - -if 0: -#if __name__ == "__main__": - import matplotlib.pyplot as plt - - fig = plt.figure(1, (4,3)) - - ax = SubplotZero(fig, 1, 1, 1) - fig.add_subplot(ax) - - ax.axis["xzero"].set_visible(True) - ax.axis["xzero"].label.set_text("Axis Zero") - - for n in ["top", "right"]: - ax.axis[n].set_visible(False) - - xx = np.arange(0, 2*np.pi, 0.01) - ax.plot(xx, np.sin(xx)) - ax.set_ylabel("Test") - plt.draw() - plt.show() - - -if __name__ == "__main__": -#if 1: - import matplotlib.pyplot as plt - - fig = plt.figure(1, (4,3)) - - ax = Subplot(fig, 1, 1, 1) - fig.add_subplot(ax) - - xx = np.arange(0, 2*np.pi, 0.01) - ax.plot(xx, np.sin(xx)) - ax.set_ylabel("Test") - - ax.axis["top"].major_ticks.set_tick_out(True) #set_tick_direction("out") - ax.axis["bottom"].major_ticks.set_tick_out(True) #set_tick_direction("out") - #ax.axis["bottom"].set_tick_direction("in") - - ax.axis["bottom"].set_label("Tk0") - - plt.draw() - plt.show() diff --git a/lib/mpl_toolkits/axisartist/clip_path.py b/lib/mpl_toolkits/axisartist/clip_path.py index ae62f1c1eca0..8507b09b0750 100644 --- a/lib/mpl_toolkits/axisartist/clip_path.py +++ b/lib/mpl_toolkits/axisartist/clip_path.py @@ -133,29 +133,3 @@ def clip_line_to_rect(xline, yline, bbox): if bbox.containsx(x)] return list(zip(lx4, ly4)), [c_left, c_bottom, c_right, c_top] - - -if __name__ == "__main__": - - import matplotlib.pyplot as plt - - x = np.array([-3, -2, -1, 0., 1, 2, 3, 2, 1, 0, -1, -2, -3, 5]) - #x = np.array([-3, -2, -1, 0., 1, 2, 3]) - y = np.arange(len(x)) - #x0 = 2 - - plt.plot(x, y, lw=1) - - from matplotlib.transforms import Bbox - bb = Bbox.from_extents(-2, 3, 2, 12.5) - lxy, ticks = clip_line_to_rect(x, y, bb) - for xx, yy in lxy: - plt.plot(xx, yy, lw=1, color="g") - - ccc = iter(["ro", "go", "rx", "bx"]) - for ttt in ticks: - cc = next(ccc) - for (xx, yy), aa in ttt: - plt.plot([xx], [yy], cc) - - #xlim( diff --git a/lib/mpl_toolkits/axisartist/floating_axes.py b/lib/mpl_toolkits/axisartist/floating_axes.py index 2e9133b877b5..bc67c7c42969 100644 --- a/lib/mpl_toolkits/axisartist/floating_axes.py +++ b/lib/mpl_toolkits/axisartist/floating_axes.py @@ -137,12 +137,12 @@ def transform_xy(x, y): xx1, yy1 = transform_xy(xx0, yy0) - xx00 = xx0.copy() + xx00 = xx0.astype(float, copy=True) xx00[xx0+dx>xmax] -= dx xx1a, yy1a = transform_xy(xx00, yy0) xx1b, yy1b = transform_xy(xx00+dx, yy0) - yy00 = yy0.copy() + yy00 = yy0.astype(float, copy=True) yy00[yy0+dy>ymax] -= dy xx2a, yy2a = transform_xy(xx0, yy00) xx2b, yy2b = transform_xy(xx0, yy00+dy) @@ -158,12 +158,12 @@ def transform_xy(x, y): xx1, yy1 = transform_xy(xx0, yy0) - yy00 = yy0.copy() + yy00 = yy0.astype(float, copy=True) yy00[yy0+dy>ymax] -= dy xx1a, yy1a = transform_xy(xx0, yy00) xx1b, yy1b = transform_xy(xx0, yy00+dy) - xx00 = xx0.copy() + xx00 = xx0.astype(float, copy=True) xx00[xx0+dx>xmax] -= dx xx2a, yy2a = transform_xy(xx00, yy0) xx2b, yy2b = transform_xy(xx00+dx, yy0) @@ -542,179 +542,3 @@ def floatingaxes_class_factory(axes_class): import matplotlib.axes as maxes FloatingSubplot = maxes.subplot_class_factory(FloatingAxes) - -# def test(fig): -# from mpl_toolkits.axes_grid.axislines import Subplot -# ax = Subplot(fig, 111) - -# fig.add_subplot(ax) - -# plt.draw() - - -def curvelinear_test3(fig): - """ - polar projection, but in a rectangular box. - """ - global ax1, axis - import numpy as np - from . import angle_helper - from matplotlib.projections import PolarAxes - - # PolarAxes.PolarTransform takes radian. However, we want our coordinate - # system in degree - tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform() - - # polar projection, which involves cycle, and also has limits in - # its coordinates, needs a special method to find the extremes - # (min, max of the coordinate within the view). - - - grid_locator1 = angle_helper.LocatorDMS(15) - # Find a grid values appropriate for the coordinate (degree, - # minute, second). - - tick_formatter1 = angle_helper.FormatterDMS() - # And also uses an appropriate formatter. Note that,the - # acceptable Locator and Formatter class is a bit different than - # that of mpl's, and you cannot directly use mpl's Locator and - # Formatter here (but may be possible in the future). - - from .grid_finder import FixedLocator - grid_locator2 = FixedLocator([2, 4, 6, 8, 10]) - - - grid_helper = GridHelperCurveLinear(tr, - extremes=(0, 360, 10, 3), - grid_locator1=grid_locator1, - grid_locator2=grid_locator2, - tick_formatter1=tick_formatter1, - tick_formatter2=None, - ) - - ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper) - - - #ax1.axis["top"].set_visible(False) - #ax1.axis["bottom"].major_ticklabels.set_axis_direction("top") - - fig.add_subplot(ax1) - - - #ax1.grid(True) - - - r_scale = 10. - tr2 = Affine2D().scale(1., 1./r_scale) + tr - grid_locator2 = FixedLocator([30, 60, 90]) - grid_helper2 = GridHelperCurveLinear(tr2, - extremes=(0, 360, - 10.*r_scale, 3.*r_scale), - grid_locator2=grid_locator2, - ) - - ax1.axis["right"] = axis = grid_helper2.new_fixed_axis("right", axes=ax1) - - ax1.axis["left"].label.set_text("Test 1") - ax1.axis["right"].label.set_text("Test 2") - - - for an in [ "left", "right"]: - ax1.axis[an].set_visible(False) - - - #grid_helper2 = ax1.get_grid_helper() - ax1.axis["z"] = axis = grid_helper.new_floating_axis(1, 7, - axes=ax1, - axis_direction="bottom") - axis.toggle(all=True, label=True) - #axis.label.set_axis_direction("top") - axis.label.set_text("z = ?") - axis.label.set_visible(True) - axis.line.set_color("0.5") - #axis.label.set_visible(True) - - - ax2 = ax1.get_aux_axes(tr) - - xx, yy = [67, 90, 75, 30], [2, 5, 8, 4] - ax2.scatter(xx, yy) - l, = ax2.plot(xx, yy, "k-") - l.set_clip_path(ax1.patch) - - -def curvelinear_test4(fig): - """ - polar projection, but in a rectangular box. - """ - global ax1, axis - import numpy as np - from . import angle_helper - from matplotlib.projections import PolarAxes - - tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform() - - grid_locator1 = angle_helper.LocatorDMS(5) - tick_formatter1 = angle_helper.FormatterDMS() - - from .grid_finder import FixedLocator - grid_locator2 = FixedLocator([2, 4, 6, 8, 10]) - - grid_helper = GridHelperCurveLinear(tr, - extremes=(120, 30, 10, 0), - grid_locator1=grid_locator1, - grid_locator2=grid_locator2, - tick_formatter1=tick_formatter1, - tick_formatter2=None, - ) - - ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper) - - - #ax1.axis["top"].set_visible(False) - #ax1.axis["bottom"].major_ticklabels.set_axis_direction("top") - - fig.add_subplot(ax1) - - - #ax1.grid(True) - - - ax1.axis["left"].label.set_text("Test 1") - ax1.axis["right"].label.set_text("Test 2") - - - for an in [ "top"]: - ax1.axis[an].set_visible(False) - - - #grid_helper2 = ax1.get_grid_helper() - ax1.axis["z"] = axis = grid_helper.new_floating_axis(1, 70, - axes=ax1, - axis_direction="bottom") - axis.toggle(all=True, label=True) - axis.label.set_axis_direction("top") - axis.label.set_text("z = ?") - axis.label.set_visible(True) - axis.line.set_color("0.5") - #axis.label.set_visible(True) - - - ax2 = ax1.get_aux_axes(tr) - - xx, yy = [67, 90, 75, 30], [2, 5, 8, 4] - ax2.scatter(xx, yy) - l, = ax2.plot(xx, yy, "k-") - l.set_clip_path(ax1.patch) - -if __name__ == "__main__": - import matplotlib.pyplot as plt - fig = plt.figure(1, figsize=(5, 5)) - fig.clf() - - #test(fig) - #curvelinear_test1(fig) - curvelinear_test4(fig) - - #plt.draw() - plt.show() diff --git a/lib/mpl_toolkits/axisartist/grid_finder.py b/lib/mpl_toolkits/axisartist/grid_finder.py index 4619b740c188..62a94b147835 100644 --- a/lib/mpl_toolkits/axisartist/grid_finder.py +++ b/lib/mpl_toolkits/axisartist/grid_finder.py @@ -338,12 +338,3 @@ def __call__(self, direction, factor, values): r = [self._format_dict.get(k, v) for k, v in zip(values, fallback_strings)] return r - - -if __name__ == "__main__": - locator = MaxNLocator() - locs, nloc, factor = locator(0, 100) - - fmt = FormatterPrettyPrint() - - print(fmt("left", None, locs)) diff --git a/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py b/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py index d2327a559def..578645148eeb 100644 --- a/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py +++ b/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py @@ -473,301 +473,3 @@ def f(): # yield xy, a, "" return f() - - - -def test3(): - - import numpy as np - from matplotlib.transforms import Transform - from matplotlib.path import Path - - class MyTransform(Transform): - input_dims = 2 - output_dims = 2 - is_separable = False - - def __init__(self, resolution): - """ - Create a new Aitoff transform. Resolution is the number of steps - to interpolate between each input line segment to approximate its - path in curved Aitoff space. - """ - Transform.__init__(self) - self._resolution = resolution - - def transform(self, ll): - x = ll[:, 0:1] - y = ll[:, 1:2] - - return np.concatenate((x, y-x), 1) - - transform.__doc__ = Transform.transform.__doc__ - - transform_non_affine = transform - transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__ - - def transform_path(self, path): - vertices = path.vertices - ipath = path.interpolated(self._resolution) - return Path(self.transform(ipath.vertices), ipath.codes) - transform_path.__doc__ = Transform.transform_path.__doc__ - - transform_path_non_affine = transform_path - transform_path_non_affine.__doc__ = Transform.transform_path_non_affine.__doc__ - - def inverted(self): - return MyTransformInv(self._resolution) - inverted.__doc__ = Transform.inverted.__doc__ - - class MyTransformInv(Transform): - input_dims = 2 - output_dims = 2 - is_separable = False - - def __init__(self, resolution): - Transform.__init__(self) - self._resolution = resolution - - def transform(self, ll): - x = ll[:, 0:1] - y = ll[:, 1:2] - - return np.concatenate((x, y+x), 1) - transform.__doc__ = Transform.transform.__doc__ - - def inverted(self): - return MyTransform(self._resolution) - inverted.__doc__ = Transform.inverted.__doc__ - - - - import matplotlib.pyplot as plt - fig = plt.figure(1) - fig.clf() - tr = MyTransform(1) - grid_helper = GridHelperCurveLinear(tr) - - - from mpl_toolkits.axes_grid1.parasite_axes import host_subplot_class_factory - from .axislines import Axes - - SubplotHost = host_subplot_class_factory(Axes) - - ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) - - fig.add_subplot(ax1) - - ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") - ax1.parasites.append(ax2) - ax2.plot([3, 6], [5.0, 10.]) - - ax1.set_aspect(1.) - ax1.set_xlim(0, 10) - ax1.set_ylim(0, 10) - - ax1.grid(True) - plt.draw() - - - -def curvelinear_test2(fig): - """ - polar projection, but in a rectangular box. - """ - global ax1 - import numpy as np - from . import angle_helper - from matplotlib.projections import PolarAxes - from matplotlib.transforms import Affine2D - - from mpl_toolkits.axes_grid.parasite_axes import SubplotHost, \ - ParasiteAxesAuxTrans - import matplotlib.cbook as cbook - - # PolarAxes.PolarTransform takes radian. However, we want our coordinate - # system in degree - tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform() - - # polar projection, which involves cycle, and also has limits in - # its coordinates, needs a special method to find the extremes - # (min, max of the coordinate within the view). - - # 20, 20 : number of sampling points along x, y direction - extreme_finder = angle_helper.ExtremeFinderCycle(20, 20, - lon_cycle = 360, - lat_cycle = None, - lon_minmax = None, - lat_minmax = (0, np.inf), - ) - - grid_locator1 = angle_helper.LocatorDMS(5) - # Find a grid values appropriate for the coordinate (degree, - # minute, second). - - tick_formatter1 = angle_helper.FormatterDMS() - # And also uses an appropriate formatter. Note that,the - # acceptable Locator and Formatter class is a bit different than - # that of mpl's, and you cannot directly use mpl's Locator and - # Formatter here (but may be possible in the future). - - grid_helper = GridHelperCurveLinear(tr, - extreme_finder=extreme_finder, - grid_locator1=grid_locator1, - tick_formatter1=tick_formatter1 - ) - - - ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) - - # make ticklabels of right and top axis visible. - ax1.axis["right"].major_ticklabels.set_visible(True) - ax1.axis["top"].major_ticklabels.set_visible(True) - - # let right axis shows ticklabels for 1st coordinate (angle) - ax1.axis["right"].get_helper().nth_coord_ticks=0 - # let bottom axis shows ticklabels for 2nd coordinate (radius) - ax1.axis["bottom"].get_helper().nth_coord_ticks=1 - - fig.add_subplot(ax1) - - grid_helper = ax1.get_grid_helper() - ax1.axis["lat"] = axis = grid_helper.new_floating_axis(0, 60, axes=ax1) - axis.label.set_text("Test") - axis.label.set_visible(True) - #axis._extremes = 2, 10 - #axis.label.set_text("Test") - #axis.major_ticklabels.set_visible(False) - #axis.major_ticks.set_visible(False) - axis.get_helper()._extremes=2, 10 - - ax1.axis["lon"] = axis = grid_helper.new_floating_axis(1, 6, axes=ax1) - #axis.major_ticklabels.set_visible(False) - #axis.major_ticks.set_visible(False) - axis.label.set_text("Test 2") - axis.get_helper()._extremes=-180, 90 - - # A parasite axes with given transform - ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") - # note that ax2.transData == tr + ax1.transData - # Anthing you draw in ax2 will match the ticks and grids of ax1. - ax1.parasites.append(ax2) - intp = cbook.simple_linear_interpolation - ax2.plot(intp(np.array([0, 30]), 50), - intp(np.array([10., 10.]), 50)) - - ax1.set_aspect(1.) - ax1.set_xlim(-5, 12) - ax1.set_ylim(-5, 10) - - ax1.grid(True) - - -def curvelinear_test3(fig): - """ - polar projection, but in a rectangular box. - """ - global ax1, axis - import numpy as np - from . import angle_helper - from matplotlib.projections import PolarAxes - from matplotlib.transforms import Affine2D - - from mpl_toolkits.axes_grid.parasite_axes import SubplotHost - - # PolarAxes.PolarTransform takes radian. However, we want our coordinate - # system in degree - tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform() - - # polar projection, which involves cycle, and also has limits in - # its coordinates, needs a special method to find the extremes - # (min, max of the coordinate within the view). - - # 20, 20 : number of sampling points along x, y direction - extreme_finder = angle_helper.ExtremeFinderCycle(20, 20, - lon_cycle = 360, - lat_cycle = None, - lon_minmax = None, - lat_minmax = (0, np.inf), - ) - - grid_locator1 = angle_helper.LocatorDMS(12) - # Find a grid values appropriate for the coordinate (degree, - # minute, second). - - tick_formatter1 = angle_helper.FormatterDMS() - # And also uses an appropriate formatter. Note that,the - # acceptable Locator and Formatter class is a bit different than - # that of mpl's, and you cannot directly use mpl's Locator and - # Formatter here (but may be possible in the future). - - grid_helper = GridHelperCurveLinear(tr, - extreme_finder=extreme_finder, - grid_locator1=grid_locator1, - tick_formatter1=tick_formatter1 - ) - - - ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) - - for axis in list(six.itervalues(ax1.axis)): - axis.set_visible(False) - - fig.add_subplot(ax1) - - grid_helper = ax1.get_grid_helper() - ax1.axis["lat1"] = axis = grid_helper.new_floating_axis(0, 130, - axes=ax1, - axis_direction="left" - ) - axis.label.set_text("Test") - axis.label.set_visible(True) - axis.get_helper()._extremes=0.001, 10 - - - - grid_helper = ax1.get_grid_helper() - ax1.axis["lat2"] = axis = grid_helper.new_floating_axis(0, 50, axes=ax1, - axis_direction="right") - axis.label.set_text("Test") - axis.label.set_visible(True) - axis.get_helper()._extremes=0.001, 10 - - ax1.axis["lon"] = axis = grid_helper.new_floating_axis(1, 10, - axes=ax1, - axis_direction="bottom") - axis.label.set_text("Test 2") - axis.get_helper()._extremes= 50, 130 - axis.major_ticklabels.set_axis_direction("top") - axis.label.set_axis_direction("top") - - grid_helper.grid_finder.grid_locator1.den = 5 - grid_helper.grid_finder.grid_locator2._nbins = 5 - - -# # A parasite axes with given transform -# ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") -# # note that ax2.transData == tr + ax1.transData -# # Anthing you draw in ax2 will match the ticks and grids of ax1. -# ax1.parasites.append(ax2) -# intp = cbook.simple_linear_interpolation -# ax2.plot(intp(np.array([0, 30]), 50), -# intp(np.array([10., 10.]), 50)) - - ax1.set_aspect(1.) - ax1.set_xlim(-5, 12) - ax1.set_ylim(-5, 10) - - ax1.grid(True) - -if __name__ == "__main__": - import matplotlib.pyplot as plt - fig = plt.figure(1, figsize=(5, 5)) - fig.clf() - - #test3() - #curvelinear_test2(fig) - curvelinear_test3(fig) - - #plt.draw() - plt.show() diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist.png new file mode 100644 index 000000000000..29ddf31eb664 Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist_labelbase.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist_labelbase.png new file mode 100644 index 000000000000..5d362e779069 Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist_labelbase.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist_ticklabels.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist_ticklabels.png new file mode 100644 index 000000000000..f79611c4e1ba Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist_ticklabels.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist_ticks.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist_ticks.png new file mode 100644 index 000000000000..e73f28643e74 Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axis_artist/axis_artist_ticks.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axislines/Subplot.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axislines/Subplot.png new file mode 100644 index 000000000000..0db52526e91e Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axislines/Subplot.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axislines/SubplotZero.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axislines/SubplotZero.png new file mode 100644 index 000000000000..8d261d4bf717 Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_axislines/SubplotZero.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_clip_path/clip_path.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_clip_path/clip_path.png new file mode 100644 index 000000000000..1f296b6d06d5 Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_clip_path/clip_path.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_floating_axes/curvelinear3.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_floating_axes/curvelinear3.png new file mode 100644 index 000000000000..6832d5dcb4be Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_floating_axes/curvelinear3.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_floating_axes/curvelinear4.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_floating_axes/curvelinear4.png new file mode 100644 index 000000000000..169bc1a3dde3 Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_floating_axes/curvelinear4.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_grid_helper_curvelinear/axis_direction.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_grid_helper_curvelinear/axis_direction.png new file mode 100644 index 000000000000..20483d07184d Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_grid_helper_curvelinear/axis_direction.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_grid_helper_curvelinear/custom_transform.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_grid_helper_curvelinear/custom_transform.png new file mode 100644 index 000000000000..e32459eed747 Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_grid_helper_curvelinear/custom_transform.png differ diff --git a/lib/mpl_toolkits/tests/baseline_images/test_axisartist_grid_helper_curvelinear/polar_box.png b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_grid_helper_curvelinear/polar_box.png new file mode 100644 index 000000000000..8121ee081795 Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_axisartist_grid_helper_curvelinear/polar_box.png differ diff --git a/lib/mpl_toolkits/tests/test_axisartist_angle_helper.py b/lib/mpl_toolkits/tests/test_axisartist_angle_helper.py new file mode 100644 index 000000000000..e0373bb6f926 --- /dev/null +++ b/lib/mpl_toolkits/tests/test_axisartist_angle_helper.py @@ -0,0 +1,145 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import re + +import numpy as np +import pytest + +from mpl_toolkits.axisartist.angle_helper import ( + FormatterDMS, FormatterHMS, select_step, select_step24, select_step360) + + +_MS_RE = ( + r'''\$ # Mathtext + ( + # The sign sometimes appears on a 0 when a fraction is shown. + # Check later that there's only one. + (?P-)? + (?P[0-9.]+) # Degrees value + {degree} # Degree symbol (to be replaced by format.) + )? + ( + (?(degree)\\,) # Separator if degrees are also visible. + (?P-)? + (?P[0-9.]+) # Minutes value + {minute} # Minute symbol (to be replaced by format.) + )? + ( + (?(minute)\\,) # Separator if minutes are also visible. + (?P-)? + (?P[0-9.]+) # Seconds value + {second} # Second symbol (to be replaced by format.) + )? + \$ # Mathtext + ''' +) +DMS_RE = re.compile(_MS_RE.format(degree=re.escape(FormatterDMS.deg_mark), + minute=re.escape(FormatterDMS.min_mark), + second=re.escape(FormatterDMS.sec_mark)), + re.VERBOSE) +HMS_RE = re.compile(_MS_RE.format(degree=re.escape(FormatterHMS.deg_mark), + minute=re.escape(FormatterHMS.min_mark), + second=re.escape(FormatterHMS.sec_mark)), + re.VERBOSE) + + +def dms2float(degrees, minutes=0, seconds=0): + return degrees + minutes / 60.0 + seconds / 3600.0 + + +@pytest.mark.parametrize('args, kwargs, expected_levels, expected_factor', [ + ((-180, 180, 10), {'hour': False}, np.arange(-180, 181, 30), 1.0), + ((-12, 12, 10), {'hour': True}, np.arange(-12, 13, 2), 1.0) +]) +def test_select_step(args, kwargs, expected_levels, expected_factor): + levels, n, factor = select_step(*args, **kwargs) + + assert n == len(levels) + np.testing.assert_array_equal(levels, expected_levels) + assert factor == expected_factor + + +@pytest.mark.parametrize('args, kwargs, expected_levels, expected_factor', [ + ((-180, 180, 10), {}, np.arange(-180, 181, 30), 1.0), + ((-12, 12, 10), {}, np.arange(-750, 751, 150), 60.0) +]) +def test_select_step24(args, kwargs, expected_levels, expected_factor): + levels, n, factor = select_step24(*args, **kwargs) + + assert n == len(levels) + np.testing.assert_array_equal(levels, expected_levels) + assert factor == expected_factor + + +@pytest.mark.parametrize('args, kwargs, expected_levels, expected_factor', [ + ((dms2float(20, 21.2), dms2float(21, 33.3), 5), {}, + np.arange(1215, 1306, 15), 60.0), + ((dms2float(20.5, seconds=21.2), dms2float(20.5, seconds=33.3), 5), {}, + np.arange(73820, 73835, 2), 3600.0), + ((dms2float(20, 21.2), dms2float(20, 53.3), 5), {}, + np.arange(1220, 1256, 5), 60.0), + ((21.2, 33.3, 5), {}, + np.arange(20, 35, 2), 1.0), + ((dms2float(20, 21.2), dms2float(21, 33.3), 5), {}, + np.arange(1215, 1306, 15), 60.0), + ((dms2float(20.5, seconds=21.2), dms2float(20.5, seconds=33.3), 5), {}, + np.arange(73820, 73835, 2), 3600.0), + ((dms2float(20.5, seconds=21.2), dms2float(20.5, seconds=21.4), 5), {}, + np.arange(7382120, 7382141, 5), 360000.0), + # test threshold factor + ((dms2float(20.5, seconds=11.2), dms2float(20.5, seconds=53.3), 5), + {'threshold_factor': 60}, np.arange(12301, 12310), 600.0), + ((dms2float(20.5, seconds=11.2), dms2float(20.5, seconds=53.3), 5), + {'threshold_factor': 1}, np.arange(20502, 20517, 2), 1000.0), +]) +def test_select_step360(args, kwargs, expected_levels, expected_factor): + levels, n, factor = select_step360(*args, **kwargs) + + assert n == len(levels) + np.testing.assert_array_equal(levels, expected_levels) + assert factor == expected_factor + + +@pytest.mark.parametrize('Formatter, regex', + [(FormatterDMS, DMS_RE), + (FormatterHMS, HMS_RE)], + ids=['Degree/Minute/Second', 'Hour/Minute/Second']) +@pytest.mark.parametrize('direction, factor, values', [ + ("left", 60, [0, -30, -60]), + ("left", 600, [12301, 12302, 12303]), + ("left", 3600, [0, -30, -60]), + ("left", 36000, [738210, 738215, 738220]), + ("left", 360000, [7382120, 7382125, 7382130]), + ("left", 1., [45, 46, 47]), + ("left", 10., [452, 453, 454]), +]) +def test_formatters(Formatter, regex, direction, factor, values): + fmt = Formatter() + result = fmt(direction, factor, values) + + prev_degree = prev_minute = prev_second = None + for tick, value in zip(result, values): + m = regex.match(tick) + assert m is not None, '"%s" is not an expected tick format.' % (tick, ) + + sign = sum(m.group(sign + '_sign') is not None + for sign in ('degree', 'minute', 'second')) + assert sign <= 1, \ + 'Only one element of tick "%s" may have a sign.' % (tick, ) + sign = 1 if sign == 0 else -1 + + degree = float(m.group('degree') or prev_degree or 0) + minute = float(m.group('minute') or prev_minute or 0) + second = float(m.group('second') or prev_second or 0) + if Formatter == FormatterHMS: + # 360 degrees as plot range -> 24 hours as labelled range + expected_value = pytest.approx((value // 15) / factor) + else: + expected_value = pytest.approx(value / factor) + assert sign * dms2float(degree, minute, second) == expected_value, \ + '"%s" does not match expected tick value.' % (tick, ) + + prev_degree = degree + prev_minute = minute + prev_second = second diff --git a/lib/mpl_toolkits/tests/test_axisartist_axis_artist.py b/lib/mpl_toolkits/tests/test_axisartist_axis_artist.py new file mode 100644 index 000000000000..95b701a10c07 --- /dev/null +++ b/lib/mpl_toolkits/tests/test_axisartist_axis_artist.py @@ -0,0 +1,97 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import matplotlib.pyplot as plt +from matplotlib.testing.decorators import image_comparison + +from mpl_toolkits.axisartist import AxisArtistHelperRectlinear +from mpl_toolkits.axisartist.axis_artist import (AxisArtist, AxisLabel, + LabelBase, Ticks, TickLabels) + + +@image_comparison(baseline_images=['axis_artist_ticks'], + extensions=['png'], style='default') +def test_ticks(): + fig, ax = plt.subplots() + + ax.xaxis.set_visible(False) + ax.yaxis.set_visible(False) + + locs_angles = [((i / 10, 0.0), i * 30) for i in range(-1, 12)] + + ticks_in = Ticks(ticksize=10, axis=ax.xaxis) + ticks_in.set_locs_angles(locs_angles) + ax.add_artist(ticks_in) + + ticks_out = Ticks(ticksize=10, tick_out=True, color='C3', axis=ax.xaxis) + ticks_out.set_locs_angles(locs_angles) + ax.add_artist(ticks_out) + + +@image_comparison(baseline_images=['axis_artist_labelbase'], + extensions=['png'], style='default') +def test_labelbase(): + fig, ax = plt.subplots() + + ax.plot([0.5], [0.5], "o") + + label = LabelBase(0.5, 0.5, "Test") + label._set_ref_angle(-90) + label._set_offset_radius(offset_radius=50) + label.set_rotation(-90) + label.set(ha="center", va="top") + ax.add_artist(label) + + +@image_comparison(baseline_images=['axis_artist_ticklabels'], + extensions=['png'], style='default') +def test_ticklabels(): + fig, ax = plt.subplots() + + ax.xaxis.set_visible(False) + ax.yaxis.set_visible(False) + + ax.plot([0.2, 0.4], [0.5, 0.5], "o") + + ticks = Ticks(ticksize=10, axis=ax.xaxis) + ax.add_artist(ticks) + locs_angles_labels = [((0.2, 0.5), -90, "0.2"), + ((0.4, 0.5), -120, "0.4")] + tick_locs_angles = [(xy, a + 180) for xy, a, l in locs_angles_labels] + ticks.set_locs_angles(tick_locs_angles) + + ticklabels = TickLabels(axis_direction="left") + ticklabels._locs_angles_labels = locs_angles_labels + ticklabels.set_pad(10) + ax.add_artist(ticklabels) + + ax.plot([0.5], [0.5], "s") + axislabel = AxisLabel(0.5, 0.5, "Test") + axislabel._set_offset_radius(20) + axislabel._set_ref_angle(0) + axislabel.set_axis_direction("bottom") + ax.add_artist(axislabel) + + ax.set_xlim(0, 1) + ax.set_ylim(0, 1) + + +@image_comparison(baseline_images=['axis_artist'], + extensions=['png'], style='default') +def test_axis_artist(): + fig, ax = plt.subplots() + + ax.xaxis.set_visible(False) + ax.yaxis.set_visible(False) + + for loc in ('left', 'right', 'bottom'): + _helper = AxisArtistHelperRectlinear.Fixed(ax, loc=loc) + axisline = AxisArtist(ax, _helper, offset=None, axis_direction=loc) + ax.add_artist(axisline) + + # Settings for bottom AxisArtist. + axisline.set_label("TTT") + axisline.major_ticks.set_tick_out(False) + axisline.label.set_pad(5) + + ax.set_ylabel("Test") diff --git a/lib/mpl_toolkits/tests/test_axisartist_axislines.py b/lib/mpl_toolkits/tests/test_axisartist_axislines.py new file mode 100644 index 000000000000..de60672822cc --- /dev/null +++ b/lib/mpl_toolkits/tests/test_axisartist_axislines.py @@ -0,0 +1,45 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.testing.decorators import image_comparison + +from mpl_toolkits.axisartist.axislines import SubplotZero, Subplot + + +@image_comparison(baseline_images=['SubplotZero'], + extensions=['png'], style='default') +def test_SubplotZero(): + fig = plt.figure() + + ax = SubplotZero(fig, 1, 1, 1) + fig.add_subplot(ax) + + ax.axis["xzero"].set_visible(True) + ax.axis["xzero"].label.set_text("Axis Zero") + + for n in ["top", "right"]: + ax.axis[n].set_visible(False) + + xx = np.arange(0, 2 * np.pi, 0.01) + ax.plot(xx, np.sin(xx)) + ax.set_ylabel("Test") + + +@image_comparison(baseline_images=['Subplot'], + extensions=['png'], style='default') +def test_Subplot(): + fig = plt.figure() + + ax = Subplot(fig, 1, 1, 1) + fig.add_subplot(ax) + + xx = np.arange(0, 2 * np.pi, 0.01) + ax.plot(xx, np.sin(xx)) + ax.set_ylabel("Test") + + ax.axis["top"].major_ticks.set_tick_out(True) + ax.axis["bottom"].major_ticks.set_tick_out(True) + + ax.axis["bottom"].set_label("Tk0") diff --git a/lib/mpl_toolkits/tests/test_axisartist_clip_path.py b/lib/mpl_toolkits/tests/test_axisartist_clip_path.py new file mode 100644 index 000000000000..7646806b2483 --- /dev/null +++ b/lib/mpl_toolkits/tests/test_axisartist_clip_path.py @@ -0,0 +1,38 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import six + +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.testing.decorators import image_comparison +from matplotlib.transforms import Bbox + +from mpl_toolkits.axisartist.clip_path import clip_line_to_rect + + +@image_comparison(baseline_images=['clip_path'], + extensions=['png'], style='default') +def test_clip_path(): + x = np.array([-3, -2, -1, 0., 1, 2, 3, 2, 1, 0, -1, -2, -3, 5]) + y = np.arange(len(x)) + + fig, ax = plt.subplots() + ax.plot(x, y, lw=1) + + bbox = Bbox.from_extents(-2, 3, 2, 12.5) + rect = plt.Rectangle(bbox.p0, bbox.width, bbox.height, + facecolor='none', edgecolor='k', ls='--') + ax.add_patch(rect) + + clipped_lines, ticks = clip_line_to_rect(x, y, bbox) + for lx, ly in clipped_lines: + ax.plot(lx, ly, lw=1, color='C1') + for px, py in zip(lx, ly): + assert bbox.contains(px, py) + + ccc = iter(['C3o', 'C2x', 'C3o', 'C2x']) + for ttt in ticks: + cc = six.next(ccc) + for (xx, yy), aa in ttt: + ax.plot([xx], [yy], cc) diff --git a/lib/mpl_toolkits/tests/test_axisartist_floating_axes.py b/lib/mpl_toolkits/tests/test_axisartist_floating_axes.py new file mode 100644 index 000000000000..de722660958f --- /dev/null +++ b/lib/mpl_toolkits/tests/test_axisartist_floating_axes.py @@ -0,0 +1,126 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import numpy as np + +import matplotlib.pyplot as plt +import matplotlib.projections as mprojections +import matplotlib.transforms as mtransforms +from matplotlib.testing.decorators import image_comparison +from mpl_toolkits.axisartist.axislines import Subplot +from mpl_toolkits.axisartist.floating_axes import ( + FloatingSubplot, + GridHelperCurveLinear) +from mpl_toolkits.axisartist.grid_finder import FixedLocator +from mpl_toolkits.axisartist import angle_helper + + +def test_subplot(): + fig = plt.figure(figsize=(5, 5)) + fig.clf() + + ax = Subplot(fig, 111) + fig.add_subplot(ax) + + +@image_comparison(baseline_images=['curvelinear3'], + extensions=['png'], style='default', tol=0.01) +def test_curvelinear3(): + fig = plt.figure(figsize=(5, 5)) + fig.clf() + + tr = (mtransforms.Affine2D().scale(np.pi / 180, 1) + + mprojections.PolarAxes.PolarTransform()) + + grid_locator1 = angle_helper.LocatorDMS(15) + tick_formatter1 = angle_helper.FormatterDMS() + + grid_locator2 = FixedLocator([2, 4, 6, 8, 10]) + + grid_helper = GridHelperCurveLinear(tr, + extremes=(0, 360, 10, 3), + grid_locator1=grid_locator1, + grid_locator2=grid_locator2, + tick_formatter1=tick_formatter1, + tick_formatter2=None) + + ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper) + fig.add_subplot(ax1) + + r_scale = 10 + tr2 = mtransforms.Affine2D().scale(1, 1 / r_scale) + tr + grid_locator2 = FixedLocator([30, 60, 90]) + grid_helper2 = GridHelperCurveLinear(tr2, + extremes=(0, 360, + 10 * r_scale, 3 * r_scale), + grid_locator2=grid_locator2) + + ax1.axis["right"] = axis = grid_helper2.new_fixed_axis("right", axes=ax1) + + ax1.axis["left"].label.set_text("Test 1") + ax1.axis["right"].label.set_text("Test 2") + + for an in ["left", "right"]: + ax1.axis[an].set_visible(False) + + axis = grid_helper.new_floating_axis(1, 7, axes=ax1, + axis_direction="bottom") + ax1.axis["z"] = axis + axis.toggle(all=True, label=True) + axis.label.set_text("z = ?") + axis.label.set_visible(True) + axis.line.set_color("0.5") + + ax2 = ax1.get_aux_axes(tr) + + xx, yy = [67, 90, 75, 30], [2, 5, 8, 4] + ax2.scatter(xx, yy) + l, = ax2.plot(xx, yy, "k-") + l.set_clip_path(ax1.patch) + + +@image_comparison(baseline_images=['curvelinear4'], + extensions=['png'], style='default', tol=0.01) +def test_curvelinear4(): + fig = plt.figure(figsize=(5, 5)) + fig.clf() + + tr = (mtransforms.Affine2D().scale(np.pi / 180, 1) + + mprojections.PolarAxes.PolarTransform()) + + grid_locator1 = angle_helper.LocatorDMS(5) + tick_formatter1 = angle_helper.FormatterDMS() + + grid_locator2 = FixedLocator([2, 4, 6, 8, 10]) + + grid_helper = GridHelperCurveLinear(tr, + extremes=(120, 30, 10, 0), + grid_locator1=grid_locator1, + grid_locator2=grid_locator2, + tick_formatter1=tick_formatter1, + tick_formatter2=None) + + ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper) + fig.add_subplot(ax1) + + ax1.axis["left"].label.set_text("Test 1") + ax1.axis["right"].label.set_text("Test 2") + + for an in ["top"]: + ax1.axis[an].set_visible(False) + + axis = grid_helper.new_floating_axis(1, 70, axes=ax1, + axis_direction="bottom") + ax1.axis["z"] = axis + axis.toggle(all=True, label=True) + axis.label.set_axis_direction("top") + axis.label.set_text("z = ?") + axis.label.set_visible(True) + axis.line.set_color("0.5") + + ax2 = ax1.get_aux_axes(tr) + + xx, yy = [67, 90, 75, 30], [2, 5, 8, 4] + ax2.scatter(xx, yy) + l, = ax2.plot(xx, yy, "k-") + l.set_clip_path(ax1.patch) diff --git a/lib/mpl_toolkits/tests/test_axisartist_grid_finder.py b/lib/mpl_toolkits/tests/test_axisartist_grid_finder.py new file mode 100644 index 000000000000..5305060366a5 --- /dev/null +++ b/lib/mpl_toolkits/tests/test_axisartist_grid_finder.py @@ -0,0 +1,16 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +from mpl_toolkits.axisartist.grid_finder import ( + FormatterPrettyPrint, + MaxNLocator) + + +def test_pretty_print_format(): + locator = MaxNLocator() + locs, nloc, factor = locator(0, 100) + + fmt = FormatterPrettyPrint() + + assert fmt("left", None, locs) == \ + [r'$\mathdefault{%d}$' % (l, ) for l in locs] diff --git a/lib/mpl_toolkits/tests/test_axisartist_grid_helper_curvelinear.py b/lib/mpl_toolkits/tests/test_axisartist_grid_helper_curvelinear.py new file mode 100644 index 000000000000..a7c637428a5f --- /dev/null +++ b/lib/mpl_toolkits/tests/test_axisartist_grid_helper_curvelinear.py @@ -0,0 +1,219 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import numpy as np + +import matplotlib.pyplot as plt +from matplotlib.path import Path +from matplotlib.projections import PolarAxes +from matplotlib.transforms import Affine2D, Transform +from matplotlib.testing.decorators import image_comparison + +from mpl_toolkits.axes_grid.parasite_axes import ParasiteAxesAuxTrans, \ + SubplotHost +from mpl_toolkits.axes_grid1.parasite_axes import host_subplot_class_factory +from mpl_toolkits.axisartist import angle_helper +from mpl_toolkits.axisartist.axislines import Axes +from mpl_toolkits.axisartist.grid_helper_curvelinear import \ + GridHelperCurveLinear + + +@image_comparison(baseline_images=['custom_transform'], + extensions=['png'], style='default', tol=0.03) +def test_custom_transform(): + class MyTransform(Transform): + input_dims = 2 + output_dims = 2 + is_separable = False + + def __init__(self, resolution): + """ + Resolution is the number of steps to interpolate between each input + line segment to approximate its path in transformed space. + """ + Transform.__init__(self) + self._resolution = resolution + + def transform(self, ll): + x = ll[:, 0:1] + y = ll[:, 1:2] + + return np.concatenate((x, y - x), 1) + + transform_non_affine = transform + + def transform_path(self, path): + vertices = path.vertices + ipath = path.interpolated(self._resolution) + return Path(self.transform(ipath.vertices), ipath.codes) + + transform_path_non_affine = transform_path + + def inverted(self): + return MyTransformInv(self._resolution) + + class MyTransformInv(Transform): + input_dims = 2 + output_dims = 2 + is_separable = False + + def __init__(self, resolution): + Transform.__init__(self) + self._resolution = resolution + + def transform(self, ll): + x = ll[:, 0:1] + y = ll[:, 1:2] + + return np.concatenate((x, y+x), 1) + + def inverted(self): + return MyTransform(self._resolution) + + fig = plt.figure() + + SubplotHost = host_subplot_class_factory(Axes) + + tr = MyTransform(1) + grid_helper = GridHelperCurveLinear(tr) + ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) + fig.add_subplot(ax1) + + ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") + ax1.parasites.append(ax2) + ax2.plot([3, 6], [5.0, 10.]) + + ax1.set_aspect(1.) + ax1.set_xlim(0, 10) + ax1.set_ylim(0, 10) + + ax1.grid(True) + + +@image_comparison(baseline_images=['polar_box'], + extensions=['png'], style='default', tol=0.03) +def test_polar_box(): + fig = plt.figure(figsize=(5, 5)) + + # PolarAxes.PolarTransform takes radian. However, we want our coordinate + # system in degree + tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform() + + # polar projection, which involves cycle, and also has limits in + # its coordinates, needs a special method to find the extremes + # (min, max of the coordinate within the view). + extreme_finder = angle_helper.ExtremeFinderCycle(20, 20, + lon_cycle=360, + lat_cycle=None, + lon_minmax=None, + lat_minmax=(0, np.inf)) + + grid_locator1 = angle_helper.LocatorDMS(12) + tick_formatter1 = angle_helper.FormatterDMS() + + grid_helper = GridHelperCurveLinear(tr, + extreme_finder=extreme_finder, + grid_locator1=grid_locator1, + tick_formatter1=tick_formatter1) + + ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) + + ax1.axis["right"].major_ticklabels.set_visible(True) + ax1.axis["top"].major_ticklabels.set_visible(True) + + # let right axis shows ticklabels for 1st coordinate (angle) + ax1.axis["right"].get_helper().nth_coord_ticks = 0 + # let bottom axis shows ticklabels for 2nd coordinate (radius) + ax1.axis["bottom"].get_helper().nth_coord_ticks = 1 + + fig.add_subplot(ax1) + + ax1.axis["lat"] = axis = grid_helper.new_floating_axis(0, 45, axes=ax1) + axis.label.set_text("Test") + axis.label.set_visible(True) + axis.get_helper()._extremes = 2, 12 + + ax1.axis["lon"] = axis = grid_helper.new_floating_axis(1, 6, axes=ax1) + axis.label.set_text("Test 2") + axis.get_helper()._extremes = -180, 90 + + # A parasite axes with given transform + ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal") + assert ax2.transData == tr + ax1.transData + # Anything you draw in ax2 will match the ticks and grids of ax1. + ax1.parasites.append(ax2) + ax2.plot(np.linspace(0, 30, 50), np.linspace(10, 10, 50)) + + ax1.set_aspect(1.) + ax1.set_xlim(-5, 12) + ax1.set_ylim(-5, 10) + + ax1.grid(True) + + +@image_comparison(baseline_images=['axis_direction'], + extensions=['png'], style='default', tol=0.03) +def test_axis_direction(): + fig = plt.figure(figsize=(5, 5)) + + # PolarAxes.PolarTransform takes radian. However, we want our coordinate + # system in degree + tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform() + + # polar projection, which involves cycle, and also has limits in + # its coordinates, needs a special method to find the extremes + # (min, max of the coordinate within the view). + + # 20, 20 : number of sampling points along x, y direction + extreme_finder = angle_helper.ExtremeFinderCycle(20, 20, + lon_cycle=360, + lat_cycle=None, + lon_minmax=None, + lat_minmax=(0, np.inf), + ) + + grid_locator1 = angle_helper.LocatorDMS(12) + tick_formatter1 = angle_helper.FormatterDMS() + + grid_helper = GridHelperCurveLinear(tr, + extreme_finder=extreme_finder, + grid_locator1=grid_locator1, + tick_formatter1=tick_formatter1) + + ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper) + + for axis in ax1.axis.values(): + axis.set_visible(False) + + fig.add_subplot(ax1) + + ax1.axis["lat1"] = axis = grid_helper.new_floating_axis( + 0, 130, + axes=ax1, axis_direction="left") + axis.label.set_text("Test") + axis.label.set_visible(True) + axis.get_helper()._extremes = 0.001, 10 + + ax1.axis["lat2"] = axis = grid_helper.new_floating_axis( + 0, 50, + axes=ax1, axis_direction="right") + axis.label.set_text("Test") + axis.label.set_visible(True) + axis.get_helper()._extremes = 0.001, 10 + + ax1.axis["lon"] = axis = grid_helper.new_floating_axis( + 1, 10, + axes=ax1, axis_direction="bottom") + axis.label.set_text("Test 2") + axis.get_helper()._extremes = 50, 130 + axis.major_ticklabels.set_axis_direction("top") + axis.label.set_axis_direction("top") + + grid_helper.grid_finder.grid_locator1.den = 5 + grid_helper.grid_finder.grid_locator2._nbins = 5 + + ax1.set_aspect(1.) + ax1.set_xlim(-8, 8) + ax1.set_ylim(-4, 12) + + ax1.grid(True) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy