Package fieldpy :: Package plotting :: Module plot_tools
[hide private]
[frames] | no frames]

Module plot_tools

source code

This module is for producing standardized plots for:

Generally a function sets the P.rcParams to values suitable for the printing.

Some features cannot be done with P.rcParams and can be done with seprarate functions.

For a description of the sizing of plot and fonts see http://www.scipy.org/Cookbook/Matplotlib/LaTeX_Examples

Short help about Date ticking

To set tick locations use:

   ax.xaxis.set_major_locator(plt.DayLocator())

Possible date locators are:

   MinuteLocator: locate minutes
   HourLocator: locate hours
   DayLocator: locate specifed days of the month
   WeekdayLocator: Locate days of the week, eg MO, TU
   MonthLocator: locate months, eg 7 for july
   YearLocator: locate years that are multiples of base
   RRuleLocator: locate using a matplotlib.dates.rrulewrapper. The rrulewrapper is a simple wrapper around a dateutils.rrule (dateutil) which allow almost arbitrary date tick specifications. See rrule example.
   AutoDateLocator: On autoscale, this class picks the best MultipleDateLocator to set the view limits and the tick locations.

More is found here: http://matplotlib.sourceforge.net/api/dates_api.html. Other non-date locators see: http://matplotlib.sourceforge.net/api/ticker_api.html

And the formatting is done with:

   ax.xaxis.set_major_formatter(plt.DateFormatter('%d'))

where format string is:

   %a      Locale's abbreviated weekday name.
   %A      Locale's full weekday name.
   %b      Locale's abbreviated month name.
   %B      Locale's full month name.
   %c      Locale's appropriate date and time representation.
   %d      Day of the month as a decimal number [01,31].
   %H      Hour (24-hour clock) as a decimal number [00,23].
   %I      Hour (12-hour clock) as a decimal number [01,12].
   %j      Day of the year as a decimal number [001,366].
   %m      Month as a decimal number [01,12].
   %M      Minute as a decimal number [00,59].
   %p      Locale's equivalent of either AM or PM.      (1)
   %S      Second as a decimal number [00,61].      (2)
   %U      Week number of the year (Sunday as the first day of the week)
           as a decimal number [00,53]. All days in a new year preceding
           the first Sunday are considered to be in week 0.      (3)
   %w      Weekday as a decimal number [0(Sunday),6].
   %W      Week number of the year (Monday as the first day of the week)
           as a decimal number [00,53]. All days in a new year preceding
           the first Monday are considered to be in week 0.      (3)
   %x      Locale's appropriate date representation.
   %X      Locale's appropriate time representation.
   %y      Year without century as a decimal number [00,99].
   %Y      Year with century as a decimal number.
   %Z      Time zone characters if no time zone exists).
   %%      A literal "%" character.
Functions [hide private]
 
pub_igs_rcparams()
This function is used to set the rcParams for publications in the Journal of Glaciology.
source code
 
pres_rcparams()
This function is used to set the rcParams for latex-beamer presentations.
source code
 
finish_up(filename, fig=None, subplot_adjust=None)
This function finishes up a plot:
source code
 
tool_no_legend_box(ax=None)
Removes the legend from the passed list of axes.
source code
 
tool_touching_subplots(fig=None, top_ticklabels=False)
Makes touching subplots and removes the xlabels in all but the lowermost subplot.
source code
 
tool_rotate_xlabels(ax=None, rotation=0)
Rotates the xlabels of ax by rotation.
source code
 
tool_get_extent(plot_fn, *args, **kwargs)
This function returns the extent of the axes when the figure is closed.
source code
 
tool_get_coords(plot_fn, ax=None, *args, **kwargs)
Returns the x&y coords from where you clicked.
source code
 
tool_underlay_with_color(x_loc, color='g', axs=None, alpha=0.3)
Underlays the axis in the list axs with a color rectangel.
source code
 
tool_make_vert_lines(x_loc, axs=None, fmt='k-.')
Makes vertical lines at x_loc.
source code
 
tool_adjust_ylabels(pos_factor=1, axs=None)
Adjust the ylabels such that they align when there are several subplots.
source code
 
tool_label_subplots(axs=None, system='abc', pos='out_right', check_axes=True, start_value=0, fontsize=None)
This function labels all the subplots in a figure.
source code
 
tool_contour_remove_litte_ones(cs, num_points)
Removes small contours with less than num_points.
source code
 
tool_set_y_extent_and_ticks_of_subplots(y_extents, y_ticks, axs=None, minor=True)
Sets the extents and ticks according to the entires in the corresponding lists.
source code
Variables [hide private]
  pt_per_inch = 72.27
in inches: 1 inch = 72.27pt (matplotlib works in inches)
  golden_mean = 0.6180339887498949
ditto
  dashes = ['--', '-', '-.', ':']
for dashed lines
  __package__ = 'fieldpy.plotting'
Function Details [hide private]

pub_igs_rcparams()

source code 

This function is used to set the rcParams for publications in the Journal of Glaciology.

It returns some useful constans:

Returns:
column_width, column_height, two_column_width, dashes

pres_rcparams()

source code 

This function is used to set the rcParams for latex-beamer presentations.

It returns some useful constans:

Returns:
column_width, column_height, two_column_width, dashes

finish_up(filename, fig=None, subplot_adjust=None)

source code 

This function finishes up a plot:

  • adjust the linewidth of the minor ticks
  • adjust the subplots if subplot_adjust is passed
  • it *save* it to the filename. File type is determined by the extension.

It sets the ticks to the width of the axes border

tool_no_legend_box(ax=None)

source code 

Removes the legend from the passed list of axes. If no arguments are passed, then plt.gcf().axes is used.

tool_touching_subplots(fig=None, top_ticklabels=False)

source code 

Makes touching subplots and removes the xlabels in all but the lowermost subplot.

Parameters:
  • fig - the figure containing the subplots. defaults to current figure.
  • top_ticklabels - if true also do ticklabels at the top

tool_get_extent(plot_fn, *args, **kwargs)

source code 

This function returns the extent of the axes when the figure is closed. Useful for figuring out the extent on date plots without hassel.

Parameters:
  • plot_fn - a function which does some plotting. does not contain a plt.show() the arguments to plot_fn can be passed in the following *args and **kwargs

tool_get_coords(plot_fn, ax=None, *args, **kwargs)

source code 

Returns the x&y coords from where you clicked. Does not respond when zooming.

Parameters:
  • plot_fn - a function which does some plotting. does not contain a plt.show() the arguments to plot_fn can be passed in the following *args and **kwargs
  • ax - if not not current axes ought to be used. Pass the number of the subplot.

tool_underlay_with_color(x_loc, color='g', axs=None, alpha=0.3)

source code 

Underlays the axis in the list axs with a color rectangel.

Parameters:
  • x_loc - (x_min, x_max) the borders of the rectangel
  • color - 'g' the color
  • axs - [axes] default [plt.gcf().axes]
  • alpha - how solid the color is

Note: on twinx() plots the lines of the first plot will be covered. use axs=axs[0:-1:2] when axs is the list of axes.

tool_make_vert_lines(x_loc, axs=None, fmt='k-.')

source code 

Makes vertical lines at x_loc.

Parameters:
  • x_loc - (x_min, x_max) the borders of the rectangel
  • axs - [axes] default [plt.gcf().axes]
  • fmt - line style

Note: on twinx() plots the lines of the first plot will be covered. use axs=axs[0:-1:2] when axs is the list of axes.

tool_adjust_ylabels(pos_factor=1, axs=None)

source code 

Adjust the ylabels such that they align when there are several subplots. Only works when the x-Axis are linked.

Note: it seems that all labels need to be either ascii or unicode. a mix leads to misalignment.

Parameters:
  • pos_factor - controls the horizontal postion. default 1 means same place as outermost label. < 1 more left, > 1 more right
  • axs - a list of axes. default plt.gcf().axes

tool_label_subplots(axs=None, system='abc', pos='out_right', check_axes=True, start_value=0, fontsize=None)

source code 

This function labels all the subplots in a figure. The labels are

Parameters:
  • axs - axes of the subplots to act on. the order of the list determines the order of the labeling.
  • system - labeling system: default 'abc', 'ABC'
  • pos - default: outside on the right (out_right), in_top_right or (x,y) in figure coordinates.
  • check_axes - if only one axes, then don't label. default:True

tool_contour_remove_litte_ones(cs, num_points)

source code 

Removes small contours with less than num_points.

Parameters:
  • cs - is a contour instance
  • num_points - min number of points

tool_set_y_extent_and_ticks_of_subplots(y_extents, y_ticks, axs=None, minor=True)

source code 

Sets the extents and ticks according to the entires in the corresponding lists.

Parameters:
  • y_extents - a list of y-extent tuples
  • y_ticks (list of lists containing floats) - the location of the yticks given for each axes.
  • axs - a list of axis (default: all axis in current figure)
  • minor - not sure

Note:

  • the y_ticks need to be floats!
  • set minor=False if using plt.twiny