util.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 #  Copyright (c) 2011, UC Regents
00004 #  All rights reserved.
00005 #
00006 #  Redistribution and use in source and binary forms, with or without
00007 #  modification, are permitted provided that the following conditions
00008 #  are met:
00009 #
00010 #   * Redistributions of source code must retain the above copyright
00011 #     notice, this list of conditions and the following disclaimer.
00012 #   * Redistributions in binary form must reproduce the above
00013 #     copyright notice, this list of conditions and the following
00014 #     disclaimer in the documentation and/or other materials provided
00015 #     with the distribution.
00016 #   * Neither the name of the University of California nor the names of its
00017 #     contributors may be used to endorse or promote products derived
00018 #     from this software without specific prior written permission.
00019 #
00020 #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 #  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 #  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 #  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 #  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 #  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 #  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 #  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 #  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 #  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 #  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 #  POSSIBILITY OF SUCH DAMAGE.
00032 
00033 import os
00034 import numpy as np
00035 import matplotlib.pyplot as plt
00036 import matplotlib.patches as mpatches
00037 
00038 def _equal_axes(ax):
00039     ax.set_aspect('equal')
00040     ax.set_aspect('equal', adjustable='datalim')
00041     
00042 def newfig(title="", xlabel="", ylabel="", equal_axes=False, grid=True, hold=True):
00043     fig = plt.figure()
00044     plt.plot(0,0,'r')
00045     ax = plt.gca()
00046     ax.set_title(title)
00047     if equal_axes:
00048         _equal_axes(ax)
00049     ax.set_xlabel(xlabel)
00050     ax.set_ylabel(ylabel)
00051     plt.grid(grid)
00052     plt.hold(hold)
00053     fmwin = plt.get_current_fig_manager().window # this might be Tkinter specific..
00054     fignum_txt = fmwin.title()
00055     fmwin.title(fignum_txt + ': ' + title)
00056     return ax
00057 
00058 def new_timeseries_fig(title="", ylabel="", grid=True, hold=True):
00059     ax = newfig(title, xlabel='time [s]', ylabel=ylabel, equal_axes=False, grid=grid, hold=hold)
00060     
00061 
00062 def plot_traj(x,y, *args, **kwargs):
00063     plt.plot(x, y, *args, **kwargs)
00064     plt.plot(x[0], y[0], 'go')
00065     plt.plot(x[-1], y[-1], 'rx')
00066     
00067 def show():
00068     plt.show()
00069     
00070 def save_all_figs(output_dir, prefix="", ext=".eps", **savefig_kwargs):
00071     fignums = plt.get_fignums()
00072     for fignum in fignums:
00073         f = plt.figure(fignum)
00074         fname = os.path.join(output_dir, prefix, ("%03d" % fignum) + ext)
00075         f.savefig(fname, orientation='landscape', **savefig_kwargs)
00076 


starmac_tools
Author(s): bouffard
autogenerated on Sun Jan 5 2014 11:38:35