Menu

[r7472]: / branches / mathtex / test / test_plots / TestPolar.py  Maximize  Restore  History

Download this file

102 lines (73 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#=======================================================================
"""The Polar unit-test class implementation."""
#=======================================================================
from mplTest import *
#=======================================================================
# Add import modules below.
import matplotlib
matplotlib.use( "Agg", warn = False )
import pylab
import numpy as npy
#
#=======================================================================
#=======================================================================
class TestPolar( MplTestCase ):
"""Polar unit test class."""
# Uncomment any appropriate tags
tags = [
# 'gui', # requires the creation of a gui window
'agg', # uses agg in the backend
'agg-only', # uses only agg in the backend
# 'wx', # uses wx in the backend
# 'qt', # uses qt in the backend
# 'ps', # uses the postscript backend
# 'units', # uses units in the test
'PIL', # uses PIL for image comparison
]
#--------------------------------------------------------------------
def setUp( self ):
"""Setup any data needed for the unit test."""
units.register()
#--------------------------------------------------------------------
def tearDown( self ):
"""Clean-up any generated files here."""
pass
#--------------------------------------------------------------------
def test_polar_wrap( self ):
"""Test polar plots where data crosses 0 degrees."""
fname = self.outFile( "polar_wrap_180.png" )
D2R = npy.pi / 180.0
fig = pylab.figure()
#NOTE: resolution=1 really should be the default
pylab.subplot( 111, polar=True, resolution=1 )
pylab.polar( [179*D2R, -179*D2R], [0.2, 0.1], "b.-" )
pylab.polar( [179*D2R, 181*D2R], [0.2, 0.1], "g.-" )
pylab.rgrids( [0.05, 0.1, 0.15, 0.2, 0.25, 0.3] )
fig.savefig( fname )
self.checkImage( fname )
fname = self.outFile( "polar_wrap_360.png" )
fig = pylab.figure()
#NOTE: resolution=1 really should be the default
pylab.subplot( 111, polar=True, resolution=1 )
pylab.polar( [2*D2R, -2*D2R], [0.2, 0.1], "b.-" )
pylab.polar( [2*D2R, 358*D2R], [0.2, 0.1], "g.-" )
pylab.polar( [358*D2R, 2*D2R], [0.2, 0.1], "r.-" )
pylab.rgrids( [0.05, 0.1, 0.15, 0.2, 0.25, 0.3] )
fig.savefig( fname )
self.checkImage( fname )
#--------------------------------------------------------------------
def test_polar_units( self ):
"""Test polar plots with unitized data."""
fname = self.outFile( "polar_units.png" )
pi = npy.pi
deg = units.UnitDbl( 1.0, "deg" )
x1 = [ pi/6.0, pi/4.0, pi/3.0, pi/2.0 ]
x2 = [ 30.0*deg, 45.0*deg, 60.0*deg, 90.0*deg ]
y1 = [ 1.0, 2.0, 3.0, 4.0]
y2 = [ 4.0, 3.0, 2.0, 1.0 ]
fig = pylab.figure()
pylab.polar( x2, y1, color = "blue" )
# polar( x2, y1, color = "red", xunits="rad" )
# polar( x2, y2, color = "green" )
fig.savefig( fname )
self.checkImage( fname )
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.