Skip to content

Axisartist testing + bugfixes #7545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make axisartist.floating_axes pseudo-tests real.
The results seem to be acceptable.
  • Loading branch information
QuLogic committed Feb 6, 2018
commit ff53c3fb291204e8ead9bd441b28aa5270e27328
176 changes: 0 additions & 176 deletions lib/mpl_toolkits/axisartist/floating_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 126 additions & 0 deletions lib/mpl_toolkits/tests/test_axisartist_floating_axes.py
Original file line number Diff line number Diff line change
@@ -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)