def test_DateFormatter(): import pylab from datetime import datetime import matplotlib.testing.jpl_units as units units.register() # Lets make sure that DateFormatter will allow us to have tick marks # at intervals of fractional seconds. t0 = datetime( 2001, 1, 1, 0, 0, 0 ) tf = datetime( 2001, 1, 1, 0, 0, 1 ) fig = pylab.figure() ax = pylab.subplot( 111 ) ax.set_autoscale_on( True ) ax.plot( [t0, tf], [0.0, 1.0], marker='o' ) # rrule = mpldates.rrulewrapper( dateutil.rrule.YEARLY, interval=500 ) # locator = mpldates.RRuleLocator( rrule ) # ax.xaxis.set_major_locator( locator ) # ax.xaxis.set_major_formatter( mpldates.AutoDateFormatter(locator) ) ax.autoscale_view() fig.autofmt_xdate() fig.savefig( 'DateFormatter_fractionalSeconds' )
def test_fill_units(): from datetime import datetime import matplotlib.testing.jpl_units as units units.register() t = units.Epoch( "ET", dt=datetime(2009, 4, 27) ) value = 10.0 * units.deg day = units.Duration( "ET", 24.0 * 60.0 * 60.0 ) fig = plt.figure() ax1 = fig.add_subplot( 221 ) ax1.plot( [t], [value], yunits='deg', color='red' ) ax1.fill( [733525.0, 733525.0, 733526.0, 733526.0], [0.0, 0.0, 90.0, 0.0], 'b' ) ax2 = fig.add_subplot( 222 ) ax2.plot( [t], [value], yunits='deg', color='red' ) ax2.fill( [t, t, t+day, t+day], [0.0, 0.0, 90.0, 0.0], 'b' ) ax3 = fig.add_subplot( 223 ) ax3.plot( [t], [value], yunits='deg', color='red' ) ax1.fill( [733525.0, 733525.0, 733526.0, 733526.0], [0*units.deg, 0*units.deg, 90*units.deg, 0*units.deg], 'b' ) ax4 = fig.add_subplot( 224 ) ax4.plot( [t], [value], yunits='deg', color='red' ) ax4.fill( [t, t, t+day, t+day], [0*units.deg, 0*units.deg, 90*units.deg, 0*units.deg], facecolor="blue" ) fig.autofmt_xdate() fig.savefig( 'fill_units' )
def test_polar_units(): import matplotlib.testing.jpl_units as units from nose.tools import assert_true units.register() pi = np.pi deg = units.UnitDbl( 1.0, "deg" ) km = units.UnitDbl( 1.0, "km" ) 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 = plt.figure() plt.polar( x2, y1, color = "blue" ) # polar( x2, y1, color = "red", xunits="rad" ) # polar( x2, y2, color = "green" ) fig = plt.figure() # make sure runits and theta units work y1 = [ y*km for y in y1 ] plt.polar( x2, y1, color = "blue", thetaunits="rad", runits="km" ) assert_true( isinstance(plt.gca().get_xaxis().get_major_formatter(), units.UnitDblFormatter) )
def test_formatter_ticker(): import matplotlib.testing.jpl_units as units units.register() # This essentially test to see if user specified labels get overwritten # by the auto labeler functionality of the axes. xdata = [ x*units.sec for x in range(10) ] ydata1 = [ (1.5*y - 0.5)*units.km for y in range(10) ] ydata2 = [ (1.75*y - 1.0)*units.km for y in range(10) ] fig = plt.figure() ax = plt.subplot( 111 ) ax.set_xlabel( "x-label 001" ) fig.savefig( 'formatter_ticker_001' ) ax.plot( xdata, ydata1, color='blue', xunits="sec" ) fig.savefig( 'formatter_ticker_002' ) ax.set_xlabel( "x-label 003" ) fig.savefig( 'formatter_ticker_003' ) ax.plot( xdata, ydata2, color='green', xunits="hour" ) ax.set_xlabel( "x-label 004" ) fig.savefig( 'formatter_ticker_004' ) # See SF bug 2846058 # https://sourceforge.net/tracker/?func=detail&aid=2846058&group_id=80706&atid=560720 ax.set_xlabel( "x-label 005" ) ax.autoscale_view() fig.savefig( 'formatter_ticker_005' )
def test_RRuleLocator(): import pylab import matplotlib.dates as mpldates import matplotlib.testing.jpl_units as units from datetime import datetime import dateutil units.register() # This will cause the RRuleLocator to go out of bounds when it tries # to add padding to the limits, so we make sure it caps at the correct # boundary values. t0 = datetime( 1000, 1, 1 ) tf = datetime( 6000, 1, 1 ) fig = pylab.figure() ax = pylab.subplot( 111 ) ax.set_autoscale_on( True ) ax.plot( [t0, tf], [0.0, 1.0], marker='o' ) rrule = mpldates.rrulewrapper( dateutil.rrule.YEARLY, interval=500 ) locator = mpldates.RRuleLocator( rrule ) ax.xaxis.set_major_locator( locator ) ax.xaxis.set_major_formatter( mpldates.AutoDateFormatter(locator) ) ax.autoscale_view() fig.autofmt_xdate() fig.savefig( 'RRuleLocator_bounds' )
def test_units_rectangle(): import matplotlib.testing.jpl_units as U U.register() p = mpatches.Rectangle((5*U.km, 6*U.km), 1*U.km, 2*U.km) fig, ax = plt.subplots() ax.add_patch(p) ax.set_xlim([4*U.km, 7*U.km]) ax.set_ylim([5*U.km, 9*U.km])
def test_axhspan_epoch(): from datetime import datetime import matplotlib.testing.jpl_units as units units.register() t0 = units.Epoch( "ET", dt=datetime(2009, 1, 20) ) tf = units.Epoch( "ET", dt=datetime(2009, 1, 21) ) dt = units.Duration( "ET", units.day.convert( "sec" ) ) fig = plt.figure() plt.axhspan( t0, tf, facecolor="blue", alpha=0.25 ) ax = plt.gca() ax.set_ylim( t0 - 5.0*dt, tf + 5.0*dt ) fig.savefig( 'axhspan_epoch' )
def test_polar_units(): import matplotlib.testing.jpl_units as units units.register() pi = np.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 = plt.figure() plt.polar( x2, y1, color = "blue" ) fig.savefig( 'polar_units' )
def test_jpl_barh_units(): from datetime import datetime import matplotlib.testing.jpl_units as units units.register() day = units.Duration("ET", 24.0 * 60.0 * 60.0) x = [0*units.km, 1*units.km, 2*units.km] w = [1*day, 2*day, 3*day] b = units.Epoch("ET", dt=datetime(2009, 4, 25)) fig, ax = plt.subplots() ax.barh(x, w, left=b) ax.set_xlim([b-1*day, b+w[-1]+1*day])
def test_DateFormatter(): import pylab from datetime import datetime import matplotlib.testing.jpl_units as units units.register() t0 = datetime( 2001, 1, 1, 0, 0, 0 ) tf = datetime( 2001, 1, 1, 0, 0, 1 ) fig = pylab.figure() ax = pylab.subplot( 111 ) ax.set_autoscale_on( True ) ax.plot( [t0, tf], [0.0, 1.0], marker='o' ) ax.autoscale_view() fig.autofmt_xdate() fig.savefig( 'DateFormatter_fractionalSeconds' )
def test_formatter_ticker(): import matplotlib.testing.jpl_units as units units.register() # This should affect the tick size. (Tests issue #543) matplotlib.rcParams["lines.markeredgewidth"] = 30 # This essentially test to see if user specified labels get overwritten # by the auto labeler functionality of the axes. xdata = [x * units.sec for x in range(10)] ydata1 = [(1.5 * y - 0.5) * units.km for y in range(10)] ydata2 = [(1.75 * y - 1.0) * units.km for y in range(10)] fig = plt.figure() ax = plt.subplot(111) ax.set_xlabel("x-label 001") fig = plt.figure() ax = plt.subplot(111) ax.set_xlabel("x-label 001") ax.plot(xdata, ydata1, color="blue", xunits="sec") fig = plt.figure() ax = plt.subplot(111) ax.set_xlabel("x-label 001") ax.plot(xdata, ydata1, color="blue", xunits="sec") ax.set_xlabel("x-label 003") fig = plt.figure() ax = plt.subplot(111) ax.plot(xdata, ydata1, color="blue", xunits="sec") ax.plot(xdata, ydata2, color="green", xunits="hour") ax.set_xlabel("x-label 004") # See SF bug 2846058 # https://sourceforge.net/tracker/?func=detail&aid=2846058&group_id=80706&atid=560720 fig = plt.figure() ax = plt.subplot(111) ax.plot(xdata, ydata1, color="blue", xunits="sec") ax.plot(xdata, ydata2, color="green", xunits="hour") ax.set_xlabel("x-label 005") ax.autoscale_view()
def test_RRuleLocator(): import pylab import matplotlib.dates as mpldates import matplotlib.testing.jpl_units as units from datetime import datetime import dateutil units.register() t0 = datetime( 1000, 1, 1 ) tf = datetime( 6000, 1, 1 ) fig = pylab.figure() ax = pylab.subplot( 111 ) ax.set_autoscale_on( True ) ax.plot( [t0, tf], [0.0, 1.0], marker='o' ) rrule = mpldates.rrulewrapper( dateutil.rrule.YEARLY, interval=500 ) locator = mpldates.RRuleLocator( rrule ) ax.xaxis.set_major_locator( locator ) ax.xaxis.set_major_formatter( mpldates.AutoDateFormatter(locator) ) ax.autoscale_view() fig.autofmt_xdate() fig.savefig( 'RRuleLocator_bounds' )
def test_formatter_ticker(): import matplotlib.testing.jpl_units as units units.register() xdata = [ x*units.sec for x in range(10) ] ydata1 = [ (1.5*y - 0.5)*units.km for y in range(10) ] ydata2 = [ (1.75*y - 1.0)*units.km for y in range(10) ] fig = plt.figure() ax = plt.subplot( 111 ) ax.set_xlabel( "x-label 001" ) fig.savefig( 'formatter_ticker_001' ) ax.plot( xdata, ydata1, color='blue', xunits="sec" ) fig.savefig( 'formatter_ticker_002' ) ax.set_xlabel( "x-label 003" ) fig.savefig( 'formatter_ticker_003' ) ax.plot( xdata, ydata2, color='green', xunits="hour" ) ax.set_xlabel( "x-label 004" ) fig.savefig( 'formatter_ticker_004' ) ax.set_xlabel( "x-label 005" ) ax.autoscale_view() fig.savefig( 'formatter_ticker_005' )
def test_DateFormatter(): import matplotlib.testing.jpl_units as units units.register() # Lets make sure that DateFormatter will allow us to have tick marks # at intervals of fractional seconds. t0 = datetime.datetime(2001, 1, 1, 0, 0, 0) tf = datetime.datetime(2001, 1, 1, 0, 0, 1) fig = plt.figure() ax = plt.subplot(111) ax.set_autoscale_on(True) ax.plot([t0, tf], [0.0, 1.0], marker='o') # rrule = mpldates.rrulewrapper( dateutil.rrule.YEARLY, interval=500 ) # locator = mpldates.RRuleLocator( rrule ) # ax.xaxis.set_major_locator( locator ) # ax.xaxis.set_major_formatter( mpldates.AutoDateFormatter(locator) ) ax.autoscale_view() fig.autofmt_xdate()
def test_RRuleLocator(): import matplotlib.testing.jpl_units as units units.register() # This will cause the RRuleLocator to go out of bounds when it tries # to add padding to the limits, so we make sure it caps at the correct # boundary values. t0 = datetime.datetime(1000, 1, 1) tf = datetime.datetime(6000, 1, 1) fig = plt.figure() ax = plt.subplot(111) ax.set_autoscale_on(True) ax.plot([t0, tf], [0.0, 1.0], marker='o') rrule = mdates.rrulewrapper(dateutil.rrule.YEARLY, interval=500) locator = mdates.RRuleLocator(rrule) ax.xaxis.set_major_locator(locator) ax.xaxis.set_major_formatter(mdates.AutoDateFormatter(locator)) ax.autoscale_view() fig.autofmt_xdate()
def test_formatter_ticker(): import matplotlib.testing.jpl_units as units units.register() # This essentially test to see if user specified labels get overwritten # by the auto labeler functionality of the axes. xdata = [ x*units.sec for x in range(10) ] ydata1 = [ (1.5*y - 0.5)*units.km for y in range(10) ] ydata2 = [ (1.75*y - 1.0)*units.km for y in range(10) ] fig = plt.figure() ax = plt.subplot( 111 ) ax.set_xlabel( "x-label 001" ) fig = plt.figure() ax = plt.subplot( 111 ) ax.set_xlabel( "x-label 001" ) ax.plot( xdata, ydata1, color='blue', xunits="sec" ) fig = plt.figure() ax = plt.subplot( 111 ) ax.set_xlabel( "x-label 001" ) ax.plot( xdata, ydata1, color='blue', xunits="sec" ) ax.set_xlabel( "x-label 003" ) fig = plt.figure() ax = plt.subplot( 111 ) ax.plot( xdata, ydata1, color='blue', xunits="sec" ) ax.plot( xdata, ydata2, color='green', xunits="hour" ) ax.set_xlabel( "x-label 004" ) # See SF bug 2846058 # https://sourceforge.net/tracker/?func=detail&aid=2846058&group_id=80706&atid=560720 fig = plt.figure() ax = plt.subplot( 111 ) ax.plot( xdata, ydata1, color='blue', xunits="sec" ) ax.plot( xdata, ydata2, color='green', xunits="hour" ) ax.set_xlabel( "x-label 005" ) ax.autoscale_view()
def test_fill_units(): from datetime import datetime import matplotlib.testing.jpl_units as units units.register() # generate some data t = units.Epoch("ET", dt=datetime(2009, 4, 27)) value = 10.0 * units.deg day = units.Duration("ET", 24.0 * 60.0 * 60.0) fig = plt.figure() # Top-Left ax1 = fig.add_subplot(221) ax1.plot([t], [value], yunits='deg', color='red') ax1.fill([733525.0, 733525.0, 733526.0, 733526.0], [0.0, 0.0, 90.0, 0.0], 'b') # Top-Right ax2 = fig.add_subplot(222) ax2.plot([t], [value], yunits='deg', color='red') ax2.fill([t, t, t + day, t + day], [0.0, 0.0, 90.0, 0.0], 'b') # Bottom-Left ax3 = fig.add_subplot(223) ax3.plot([t], [value], yunits='deg', color='red') ax3.fill([733525.0, 733525.0, 733526.0, 733526.0], [0 * units.deg, 0 * units.deg, 90 * units.deg, 0 * units.deg], 'b') # Bottom-Right ax4 = fig.add_subplot(224) ax4.plot([t], [value], yunits='deg', color='red') ax4.fill([t, t, t + day, t + day], [0 * units.deg, 0 * units.deg, 90 * units.deg, 0 * units.deg], facecolor="blue") fig.autofmt_xdate() fig.savefig('fill_units')
def test_fill_units(): from datetime import datetime import matplotlib.testing.jpl_units as units units.register() # generate some data t = units.Epoch("ET", dt=datetime(2009, 4, 27)) value = 10.0 * units.deg day = units.Duration("ET", 24.0 * 60.0 * 60.0) fig = plt.figure() # Top-Left ax1 = fig.add_subplot(221) ax1.plot([t], [value], yunits="deg", color="red") ax1.fill([733525.0, 733525.0, 733526.0, 733526.0], [0.0, 0.0, 90.0, 0.0], "b") # Top-Right ax2 = fig.add_subplot(222) ax2.plot([t], [value], yunits="deg", color="red") ax2.fill([t, t, t + day, t + day], [0.0, 0.0, 90.0, 0.0], "b") # Bottom-Left ax3 = fig.add_subplot(223) ax3.plot([t], [value], yunits="deg", color="red") ax3.fill( [733525.0, 733525.0, 733526.0, 733526.0], [0 * units.deg, 0 * units.deg, 90 * units.deg, 0 * units.deg], "b" ) # Bottom-Right ax4 = fig.add_subplot(224) ax4.plot([t], [value], yunits="deg", color="red") ax4.fill([t, t, t + day, t + day], [0 * units.deg, 0 * units.deg, 90 * units.deg, 0 * units.deg], facecolor="blue") fig.autofmt_xdate()