Package ComboCode :: Package cc :: Package plotting :: Module Plotting2
[hide private]
[frames] | no frames]

Module Plotting2

source code

Preliminary plotting package in Pylab.

Author: R. Lombaert

Functions [hide private]
string
plotTiles(data, cfg='', **kwargs)
Plot data in tiles in a single figure.
source code
string
plotCols(x=[], y=[], xerr=[], yerr=[], cfg='', **kwargs)
Plot a spectrum, with or without a number of subplots.
source code
str
saveFig(filename, extension='pdf', landscape=0)
Save a figure to a filename for a given extension.
source code
(list[string],list[string])
setLineTypes(n, line_types, extra_line_types=None)
Set the line types for this plot.
source code
 
setLineLabels(line_labels, line_label_spectrum, fontsize_label, y_pos, line_label_color, line_label_lines, baseline_line_labels, no_line_label_text, short_label_lines, line_label_types, linewidth, xmin, xmax, line_label_dashedvib)
Set the line labels in a plot.
source code
list(str)
getLineTypes(black=0)
Make linetypes from a list of colors and line types.
source code
string, string
splitLineType(lp)
Split a line style string in its color and line type components.
source code
list[array], list[array]
makeHistoPlot(x, y, indices=[])
[DEPRECATED] -- not used by Plotting2 anymore.
source code
dict
readCfg(cfg)
Read a cfg file.
source code
Variables [hide private]
  __package__ = 'ComboCode.cc.plotting'
Function Details [hide private]

plotTiles(data, cfg='', **kwargs)

source code 

Plot data in tiles in a single figure.

The number of tiles in the x and y direction can be specified by the dimensions keyword.

The data are then given in the form of a dictionary, in which each entry describes the contents of a single tile. These dictionaries are passed in a list of which the length is x-dim * y-dim. Can be less, but then no data will be plotted in the final # tiles.

If length is less, and the keytags keyword is included, the keytags will be put in the final tile. This only works if all data dicts have the same amount of data lists.

The same line types are used for all tiles. They can be specified as well as left to the default.

General properties can also be passed as extra keywords or as a cfg file, as with the plotCols() method.

Parameters:
  • data (list[dict]) - The data to be plotted. This list contains dictionaries that include all information of a single tile in the plot.

    Must be included in the dictionary:

    x: list of lists giving the x-coords

    y: list of lists giving the y-coords

    Possible keywords in the dicts are:

    xerr: List of arrays of x-errors. if [] no errors are included on the plot. must have same len() as x, include None in the list for data that have to be plotted without errors. If upper and lower limits differ, instead of single array for xerri, a list with two elements can be given as well with two lists: one for the upper limit and one for the lower limit

    yerr: List of arrays of y-errors. if [] no errors are included on the plot. must have same len() as y, include None in the list for data that have to be plotted without errors. If upper and lower limits differ, instead of single array for yerri, a list with two elements can be given as well with two lists: one for the upper limit and one for the lower limit

    labels: (labels, string, x-, y-position) for label in a list, default []

    histoplot: list of indices of data lists to plot as histogram, default []

    xmin, xmax, ymin and ymax: floats, default None

    line_labels: (string,x-pos,same type-integer (eg molecule fi), vibrational?) for label indicating emission lines, default []

    xaxis: name of x axis (TeX enabled), if keyword not included here, the method's xaxis is used. If not wanted, use empty string

    yaxis: name of y axis (TeX enabled), if keyword not included here, the method's yaxis is used. If not wanted, use empty string

  • dimensions (tuple(int)) - The number of tiles in the x and y direction is given: (x-dim,y-dim)

    (default: (1,len(data))

  • cfg (string/dict) - config filename read as a dictionary, can replace any keyword given to plotCols. Can also be a dictionary itself, in which case no file is read and the kwargs are updated with the content of cfg

    (default: '')

  • filename (string) - filename of the figure, without extension and with path, if None, the plot is just shown and not saved

    (default: None)

  • extension (string/list) - extension of the plot filename, adds dot if not present If None, three outputfiles are created: png, eps, pdf Multiple extensions can be requested at the same time through a list.

    (default: pdf)

  • figsize (tuple(float,float)) - the size of the figure, default is A4 page ratio

    (default: (20.*np.sqrt(2.), 20.) )

  • show_plot (bool) - show fig before saving (hit enter to continue to save)

    (default: 0)

  • xaxis (string) - name of x axis (TeX enabled)

    (default: r'$\lambda\ (\mu m)$')

  • yaxis (string) - name of y axis (TeX enabled)

    (default: r'$F_\nu (Jy)$')

  • fontsize_key (int) - fontsize of the keys

    (default: 16)

  • fontsize_axis (int) - fontsize axis labels

    (default: 24)

  • fontsize_title (int) - fontsize title

    (default: 26)

  • fontsize_label (int) - fontsize of the labels

    (default: 12)

  • fontsize_ticklabels (int) - fontsize of axis tick labels

    (default: 20)

  • bold_ticklabels (bool) - boldface axis tick labels

    (default: 0)

  • size_ticklines (float) - The relative size of the tick lines

    (default: 10)

  • legend_numpoints (int) - Number of points in the legend lines.

    (default: 1)

  • keytags (list[string]) - if default no keys, else a key for every dataset in y in all tiles. Is included in the final tile, so len of dicts in data has to be x-dim * y-dim - 1

    (default: [])

  • line_label_types (list[string]) - line types for line labels if requested. Overridden if number doesn't match number of different labels requested.

    (default: [])

  • line_label_color (bool) - give different color to a linelabel based on an integer. Black if off. If line_label_types are given, this keyword is ignored.

    (default: 0)

  • line_label_lines (bool) - put vertical lines where linelabels occur will be put at the x-position

    (default: 0)

  • baseline_line_labels (bool) - linelabels at the baseline instead of at the bottom

    (default: 0)

  • no_line_label_text (bool) - Don't show text for line labels, only lines are shown if requested.

    (default: 0)

  • short_label_lines (bool) - The label lines are short and at the top of plot

    (default:0)

  • line_label_spectrum (bool) - linelabels are set at the top and bottom of the spectrum, as for PACS spectra. If 2, all labels are set at the top.

    (default: 0)

  • line_label_linewidth (int) - The line width of line label lines.

    (default: 2)

  • line_label_dashedvib (bool) - Use dashed lines for vibrational transitions in line label lines. Only applied if the ground state label line is a full line.

    (default: 0)

  • linewidth (int) - width of all the lines in the plot

    (default: 1)

  • thick_lw_data (bool) - Use twice the linewidth for data points (through histoplot keyword).

    (default: 0)

  • xlogscale (bool) - set logarithmic scale of x-axis

    (default: 0)

  • ylogscale (bool) - set logarithmic scale of y-axis

    (default: 0)

  • xmin (float) - if default then autoscaling is done, otherwise min x value. Only used when ddict entries are not defined.

    (default: None)

  • xmax (float) - if default then autoscaling is done, otherwise max x value Only used when ddict entries are not defined.

    (default: None)

  • ymin (float) - if default then autoscaling is done, otherwise min y value Only used when ddict entries are not defined.

    (default: None)

  • ymax (float) - if default then autoscaling is done, otherwise max y value Only used when ddict entries are not defined.

    (default: None)

  • transparent (bool) - for a transparent background

    (default: 0)

  • removeYvalues (bool) - remove all Y tickmarks on the Y axis

    (default: 0)

  • removeXvalues (bool) - remove all X tickmarks on the X axis

    (default: 0)

  • line_types (list[string]) - if empty, standard line types are used if an entry is 0, standard line types are used line types are pythonesque ('-k', line style + color) if list is not empty, take len equal to len(x)

    (default: [])

    Colors:

    • r: red
    • y: yellow
    • b: blue
    • c: cyan
    • g: green
    • k: black
    • m: magenta
    • [0 and 1]: grayscale (always as a 3-digit float, e.g. 0.75!!)

    Styles:

    • -: line
    • s: squares
    • o: large filled circles
    • .: small filled circles
    • --: stripes
    • -.: stripe-point line
    • x: crosses
    • +: pluses
    • p: pentagons
    • d: filled circle + vertical line
    • |: vertical line
    • h,H: different hexagons
    • *: stars
    • 2,3,4: "triple crosses" in different orientations
    • v,>,<,^: Triangles in different orientations
  • wspace (float) - Adjust the width between subplots horizontally

    (default: 0.2)

  • hspace (float) - Adjust the width between subplots vertically

    (default: 0.2)

  • ws_bot (float) - Adjust the amount of white space at the bottom

    (default: 0.1)

  • ws_top (float) - Adjust the amount of white space at the top

    (default: 0.9)

  • ws_left (float) - Adjust the amount of white space at the left

    (default: 0.125)

  • ws_right (float) - Adjust the amount of white space at the bottom

    (default: 0.9)

  • landscape (bool) - Save the plot in landscape orientation

    (default: 0)

  • markeredgewidth (int) - Increase the linewidth of marker edges (eg black circles around colored points) or the thickness of crosses, dots, etc... Also used for the size of error bar caps.

    (default: 1)

Returns: string
the plotfilename with extension is returned

plotCols(x=[], y=[], xerr=[], yerr=[], cfg='', **kwargs)

source code 

Plot a spectrum, with or without a number of subplots.

Pylab can be made to show the plot before saving, and will do so anyway if the filename is not defined, in which case no file will be saved.

The Pylab figure types can be used here, by setting the extension keyword.

Parameters:
  • x (list[list/arrays/...]) - List of lists/arrays of x-values, requires inputfilenames if []

    (default: [])

  • y (list[list/arrays/...]) - List of lists/arrays of y-values, requires inputfilenames if []

    (default: [])

  • xerr (list[list/arrays/...]) - lists with syntax: xerr[xerri] or xerr[[xerri_low,xerri_up]] if [] no errors are included on the plot Must have same len() as x, include None in the list for data that have to be plotted without errors, while other data do have errors associated with them. If upper and lower limits differ, instead of single array/list for xerri, a list with two elements can be given as well with two lists: one for the upper limit and one for the lower limit For now errorbar color is same as data color

    (default: [])

  • yerr (list[list/arrays/...]) - List of lists/arrays of y-errs if [] no errors are included on the plot Must have same len() as y, include None in the list for data that have to be plotted without errors, while other data do have errors associated with them. For now errorbar color is same as data color If upper and lower limits differ, instead of single array/list for yerri, a list with two elements can be given as well with two lists: one for the upper limit and one for the lower limit

    (default: [])

  • twiny_x (list[array]) - If a second list of datasets has to be plotted with a different yaxis, include the second x axis data here. Only works for two different y axes, with a single x axis.

    (default: [])

  • twiny_y (list[array]) - If a second list of datasets has to be plotted with a different yaxis, include the second y axis data here. Only works for two different y axes, with a single x axis.

    (default: [])

  • inputfiles (list[string]) - list of filenames with two up to six input columns (x|y) or (x|y|xerr) or (x|y|xerr|yerr) or (x|y|xerr_low|xerr_up|yerr_low|yerr_up) If no yerr, three columns will do. If yerr, xerr must be included as well. Use 0's if there is no error on x. If upper and lower limits differ, then include 6 columns in total. Cols 3 and 4 are xerr_low and xerr_up respectively. Cols 5 and 6 are yerr_low and yerr_up respectively. All 6 must be included in this case! No combinations possible.

    (default: [])

  • cfg (string/dict) - config filename read as a dictionary, can replace any keyword given to plotCols. Can also be a dictionary itself, in which case no file is read and the kwargs are updated with the content of cfg

    (default: '')

  • filename (string) - filename of the figure, without extension and with path, if None, the plot is just shown and not saved

    (default: None)

  • extension (string/list) - extension of the plot filename, adds dot if not present If None, three output files are created: png, eps, pdf Multiple extensions can be requested at the same time through a list.

    (default: pdf)

  • number_subplots (int) - #subplots in which to plot in vertical direction

    (default: 1)

  • figsize (tuple(float,float)) - the size of the figure, A4 page ratio is (20.*np.sqrt(2.), 20.). Default is other ratio.

    (default: (12.5,8) )

  • show_plot (bool) - show fig before saving (hit enter to continue to save)

    (default: 0)

  • xaxis (string) - name of x axis (TeX enabled)

    (default: r'$\lambda\ (\mu m)$')

  • all_xaxislabels (bool) - Include xaxis labels for every subplot, in case number_subplots != 1. If off, only the bottom subplot gets an xaxis label.

    (default: 0)

  • yaxis (string) - name of y axis (TeX enabled)

    (default: r'$F_\nu (Jy)$')

  • twinyaxis (string) - name of twin y axis (TeX enabled) if twinx and twiny are not empty. If this is None then the twiny_x and twin_y are ignored. Also ignored if number_subplots!=1

    (default: None)

  • plot_title (string) - plot title (TeX enabled), if empty string no title is used

    (default: '')

  • fontsize_key (int) - fontsize of the keys

    (default: 20)

  • fontsize_axis (int) - fontsize axis labels

    (default: 26)

  • fontsize_title (int) - fontsize title

    (default: 26)

  • fontsize_label (int) - fontsize of the labels

    (default: 18)

  • fontsize_localized_label (int) - fontsize of the localized labels

    (default: 18)

  • fontsize_ticklabels (int) - fontsize of axis tick labels

    (default: 26)

  • bold_ticklabels (bool) - boldface axis tick labels

    (default: 0)

  • legend_numpoints (int) - Number of points in the legend lines.

    (default: 1)

  • keytags (list[string]) - if default no keys, else a key for every dataset in y

    (default: [])

  • twiny_keytags (list[string]) - as keytags, but only if not twinyaxis is None.

    (default: [])

  • size_ticklines (float) - The relative size of the tick lines

    (default: 10)

  • labels (list[(string,float,float)]) - string, x-, y-position for label, positions in fig coords: 0.0 bottom left, 1,1 upper right

    (default: [])

  • localized_labels (list[(string,float,float,string)]) - Same as labels, but with the xpos given in axis coordinates instead of figure coordinates. Useful for labels you only want to appear in multi-subplot figures in certain subplots. In addition the color of the text is given as an extra entry.

    (default: [])

  • line_labels (list[(string,float,int)]) - (string,x-pos and same type-integer (eg molecule fi), vibrational?) for the label,specifically to indicate emission lines

    (default: [])

  • line_label_types (list[string]) - line types for line labels if requested. Overridden if number doesn't match number of different labels requested.

    (default: [])

  • line_label_color (bool) - give different color to a linelabel based on an integer. Black if off. If line_label_types are given, this keyword is ignored.

    (default: 0)

  • line_label_lines (bool) - put vertical lines where linelabels occur will be put at the x-position

    (default: 0)

  • baseline_line_labels (bool) - linelabels at the baseline instead of at the bottom

    (default: 0)

  • line_label_spectrum (bool) - linelabels are set at the top and bottom of the spectrum, as for PACS spectra. If 2, all labels are set at the top.

    (default: 0)

  • no_line_label_text (bool) - Don't show text for line labels, only lines are shown if requested.

    (default: 0)

  • short_label_lines (bool) - The label lines are short and at the top of plot

    (default:0)

  • line_label_linewidth (int) - The line width of line label lines.

    (default: 2)

  • line_label_dashedvib (bool) - Use dashed lines for vibrational transitions in line label lines. Only applied if the ground state label line is a full line.

    (default: 0)

  • markeredgewidth (int) - Increase the linewidth of marker edges (eg black circles around colored points) or the thickness of crosses, dots, etc...

    (default: 1)

  • xerr_markeredgewidth (int) - The linewidth of the caps of x error bars.

    (default: 1)

  • yerr_markeredgewidth (int) - The linewidth of the caps of y error bars.

    (default: 1)

  • xerr_capsize (int) - The size or length of the caps on the x error bars.

    (default: 5)

  • yerr_capsize (int) - The size or length of the caps on the y error bars.

    (default: 5)

  • thick_lw_data (bool) - Use twice the linewidth for data points (through histoplot keyword).

    (default: 0)

  • linewidth (int) - width of the non-symbol line types

    (default: 3)

  • xerr_linewidth (int) - width of the x error bars

    (default: linewidth/2.)

  • yerr_linewidth (int) - width of the y error bars

    (default: linewidth/2.)

  • key_location (tuple/str) - location of the key in the plot in figure coords. Can be 'best' as well to allow python to figure out the best location

    (default: 'best' )

  • xlogscale (bool) - set logarithmic scale of x-axis

    (default: 0)

  • ylogscale (bool) - set logarithmic scale of y-axis

    (default: 0)

  • twiny_logscale (bool) - set logarithmic scale of the twiny-axis

    (default: 0)

  • xmin (float) - if default then autoscaling is done, otherwise min x value

    (default: None)

  • xmax (float) - if default then autoscaling is done, otherwise max x value

    (default: None)

  • ymin (float) - if default then autoscaling is done, otherwise min y value

    (default: None)

  • ymax (float) - if default then autoscaling is done, otherwise max y value

    (default: None)

  • twiny_ymin (float) - if default then autoscaling is done, otherwise min y value for the twiny axis

    (default: None)

  • twiny_ymax (float) - if default then autoscaling is done, otherwise min y value for the twiny axis

    (default: None)

  • transparent (bool) - for a transparent background

    (default: 0)

  • removeYvalues (bool) - remove all Y tickmarks on the Y axis

    (default: 0)

  • removeXvalues (bool) - remove all X tickmarks on the X axis

    (default: 0)

  • histoplot (list) - plot as histogram for data indices given in this list respective to their positions in the x and y inputlists

    (default: [])

  • line_types (list[string]) - if empty, standard line types are used if an entry is 0, standard line types are used line types are pythonesque ('-k', line style + color) if list is not empty, take len equal to len(x)

    (default: [])

    Colors:

    • r: red
    • y: yellow
    • b: blue
    • c: cyan
    • g: green
    • k: black
    • m: magenta
    • [0 and 1]: grayscale (always as a 3-digit float, e.g. 0.75!!)

    Styles:

    • -: line
    • s: squares
    • o: large filled circles
    • .: small filled circles
    • --: stripes
    • -.: stripe-point line
    • x: crosses
    • +: pluses
    • p: pentagons
    • d: filled circle + vertical line
    • |: vertical line
    • h,H: different hexagons
    • *: stars
    • 2,3,4: "triple crosses" in different orientations
    • v,>,<,^: Triangles in different orientations
  • markersize (list) - Give different markersize for each x-plot here. If a single number, the markersize is used for all datasets Default values are set to 5.

    (default: [])

  • zorder (list) - List that matches the x and y grids. Number gives the index of the layer that is requested for the respective datasets. Higher number means the datasets will be on top of lower numbered datasets. Default goes for no preferred ordering.

    (default: [])

  • alpha (list) - List that matches the x and y grids. Values give the opacity of the plotted curve.

    (default: [])

  • twiny_line_types (list[string]) - As line_types, but for the twiny data.

    (default: [])

  • horiz_lines (list[float]) - a list of y-coords to put full black horizontal lines

    (default: [])

  • horiz_rect (list[tuple]) - a list of tuples to set a horizontal colored transparent rectangle on the plot. tuple(y1,y2,color)

    (default: [])

  • vert_lines (list[float]) - a list of x-coords to put full black vertical lines

    (default: [])

  • vert_rect (list[tuple]) - a list of tuples to set a vertical colored transparent rectangle on the plot. tuple(x1,x2,color)

    (default: [])

  • ws_bot (float) - Adjust the amount of white space at the bottom

    (default: 0.1)

  • ws_top (float) - Adjust the amount of white space at the top

    (default: 0.9)

  • ws_left (float) - Adjust the amount of white space at the left

    (default: 0.125)

  • ws_right (float) - Adjust the amount of white space at the bottom

    (default: 0.9)

  • hspace (float) - Adjust the width between subplots vertically

    (default: 0.2)

  • landscape (bool) - Save the plot in landscape orientation

    (default: 0)

  • arrows (list[list]) - Draw arrows in a plot. (x0,y0,delta(x),delta(y),width,col,zorder) works like localized_labels.

    (default: [])

Returns: string
the plotfilename with extension is returned

saveFig(filename, extension='pdf', landscape=0)

source code 

Save a figure to a filename for a given extension.

Parameters:
  • filename (str) - The full path+filename of the figure, except the extension
  • extension (list(str)) - The extension of the figure requested. Can be a list. If None, figures are saved in .pdf, .png, and .eps.

    (default: pdf)

  • landscape (bool) - Save the figure in landscape mode.

    (default: 0)

Returns: str
The full filename with extension

setLineTypes(n, line_types, extra_line_types=None)

source code 

Set the line types for this plot.

If they are given as input, nothing is changed.

If the input is wrong, they are given by default values.

Zeroes in the input are also replaced by defaults.

Parameters:
  • n (list[array]) - Number of line types requested in total
  • line_types (list[string]) - The input value for the line_types
  • extra_line_types (list[string]) - The pool of extra line_types, which is destroyed as defaults are used. If None, they are auto generated at first.

    (default: None)

Returns: (list[string],list[string])
The set line types and default pool of line types (possibly smaller than the input value)

setLineLabels(line_labels, line_label_spectrum, fontsize_label, y_pos, line_label_color, line_label_lines, baseline_line_labels, no_line_label_text, short_label_lines, line_label_types, linewidth, xmin, xmax, line_label_dashedvib)

source code 

Set the line labels in a plot.

Parameters:
  • line_labels (list(tuple)) - The line labels to be set including (labels,x_pos,mol_index,vibrational)
  • line_label_spectrum (bool) - linelabels are set at the top and bottom of the spectrum, as for PACS spectra. If 2, all labels are set at the top.
  • fontsize_label (int) - fontsize of the labels
  • y_pos (float) - The y position of the label if line_label_spectrum is False
  • line_label_color (bool) - Color the line labels and lines
  • line_label_lines (bool) - Draw vertical lines at the label
  • baseline_line_labels (bool) - Put the line labels at the baseline or the bottom of the plot
  • no_line_label_text (bool) - Don't show text for line labels, only lines are shown if requested.
  • short_label_lines (bool) - The label lines are short and at the top of plot
  • line_label_types (list) - The line types for the line label lines.
  • linewidth (int) - line width of the line label lines.
  • xmin (float) - The minimum allowed x value for the line labels
  • xmax (float) - The maximum allowed x value for the line labels
  • line_label_dashedvib (bool) - Use dashed lines for vibrational transitions in line label lines. Only applied if the ground state label line is a full line.

getLineTypes(black=0)

source code 

Make linetypes from a list of colors and line types.

Parameters:
  • black (bool) - Return only black colors

    (Default: 0)

Returns: list(str)
The linetypes

splitLineType(lp)

source code 

Split a line style string in its color and line type components.

Note that grayscale values should always be given as a four-character string that represents a float between 0 and 1.

Parameters:
  • lp (string) - the line type string, eg '.-k'
Returns: string, string
two string, the first giving the line type, the second the color

makeHistoPlot(x, y, indices=[])

source code 

[DEPRECATED] -- not used by Plotting2 anymore.

Convert x and y data into input for an unbinned 'histogram' plot.

(by Pieter de Groote)

Parameters:
  • x (list[array/list]) - input x-values
  • y (list[array/list]) - input y-values
  • indices (list[int]) - Make a histogram plot if list is not empty. List holds indices of input data lists for the ones that will be shaped as a histogram. The others will be plotted as normal.

    default: []

Returns: list[array], list[array]
the converted x and y data -- xo, yo

readCfg(cfg)

source code 

Read a cfg file.

Parameters:
  • cfg (string) - path to the config file. If default, the hard-coded default plotting options are used.
Returns: dict
The contents of the cfg file are returned.