CMS 3D CMS Logo

Classes | Functions | Variables

public_plots_tools Namespace Reference

Classes

class  ColorScheme

Functions

def AddLogo
def DarkenColor
def InitMatplotlib
def LatexifyUnits
def RoundAwayFromZero
def SavePlot

Variables

tuple FONT_PROPS_AX_TITLE = FontProperties(size="x-large", weight="bold")
tuple FONT_PROPS_SUPTITLE = FontProperties(size="x-large", weight="bold", stretch="condensed")
tuple FONT_PROPS_TICK_LABEL = FontProperties(size="large", weight="bold")
tuple FONT_PROPS_TITLE = FontProperties(size="large", weight="regular")

Function Documentation

def public_plots_tools::AddLogo (   logo_name,
  ax,
  zoom = 1.2 
)
Read logo from PNG file and add it to axes.

Definition at line 39 of file public_plots_tools.py.

00040                                     :
00041     """Read logo from PNG file and add it to axes."""
00042 
00043     logo_data = read_png(logo_name)
00044     fig_dpi = ax.get_figure().dpi
00045     fig_size = ax.get_figure().get_size_inches()
00046     # NOTE: This scaling is kinda ad hoc...
00047     zoom_factor = .1 / 1.2 * fig_dpi * fig_size[0] / np.shape(logo_data)[0]
00048     zoom_factor *= zoom
00049     logo_box = OffsetImage(logo_data, zoom=zoom_factor)
00050     ann_box = AnnotationBbox(logo_box, [0., 1.],
00051                              xybox=(2., -3.),
00052                              xycoords="axes fraction",
00053                              boxcoords="offset points",
00054                              box_alignment=(0., 1.),
00055                              pad=0., frameon=False)
00056     ax.add_artist(ann_box)
00057     # End of AddLogo().

def public_plots_tools::DarkenColor (   color_in)
Takes a tuple (r, g, b) as input.

Definition at line 97 of file public_plots_tools.py.

00098                          :
00099     """Takes a tuple (r, g, b) as input."""
00100 
00101     color_tmp = matplotlib.colors.colorConverter.to_rgb(color_in)
00102 
00103     tmp = rgb_to_hls(*color_tmp)
00104     color_out = hls_to_rgb(tmp[0], .7 * tmp[1], tmp[2])
00105 
00106     # End of DarkenColor().
00107     return color_out

def public_plots_tools::InitMatplotlib ( )
Just some Matplotlib settings.

Definition at line 26 of file public_plots_tools.py.

00027                     :
00028     """Just some Matplotlib settings."""
00029     matplotlib.rcParams["text.usetex"] = False
00030     matplotlib.rcParams["legend.numpoints"] = 1
00031     matplotlib.rcParams["figure.figsize"] = (8., 6.)
00032     matplotlib.rcParams["figure.dpi"] = 300
00033     matplotlib.rcParams["savefig.dpi"] = matplotlib.rcParams["figure.dpi"]
00034     matplotlib.rcParams["font.size"] = 10.8
00035     matplotlib.rcParams["pdf.fonttype"] = 42
00036     # End of InitMatplotlib().

def public_plots_tools::LatexifyUnits (   units_in)

Definition at line 73 of file public_plots_tools.py.

00074                            :
00075 
00076     latex_units = {
00077         "b^{-1}" : "$\mathbf{b}^{-1}$",
00078         "mb^{-1}" : "$\mathbf{mb}^{-1}$",
00079         "ub^{-1}" : "$\mu\mathbf{b}^{-1}$",
00080         "nb^{-1}" : "$\mathbf{nb}^{-1}$",
00081         "pb^{-1}" : "$\mathbf{pb}^{-1}$",
00082         "fb^{-1}" : "$\mathbf{fb}^{-1}$",
00083         "Hz/b" : "$\mathbf{Hz/b}$",
00084         "Hz/mb" : "$\mathbf{Hz/mb}$",
00085         "Hz/ub" : "$\mathbf{Hz/}\mathbf{\mu}\mathbf{b}$",
00086         "Hz/nb" : "$\mathbf{Hz/nb}$",
00087         "Hz/pb" : "$\mathbf{Hz/pb}$",
00088         "Hz/fb" : "$\mathbf{Hz/fb}$"
00089         }
00090 
00091     res = latex_units[units_in]
00092 
00093     # End of LatexifyUnits().
00094     return res

def public_plots_tools::RoundAwayFromZero (   val)

Definition at line 60 of file public_plots_tools.py.

00061                           :
00062 
00063     res = None
00064     if val < 0.:
00065         res = math.floor(val)
00066     else:
00067         res = math.ceil(val)
00068 
00069     # End of RoundAwayFromZero().
00070     return res

def public_plots_tools::SavePlot (   fig,
  file_name_base 
)
Little helper to save plots in various formats.

Definition at line 208 of file public_plots_tools.py.

00209                                  :
00210     """Little helper to save plots in various formats."""
00211 
00212     # DEBUG DEBUG DEBUG
00213     # Check some assumptions.
00214     assert len(fig.axes) == 2
00215     assert len(fig.axes[0].artists) == 1
00216     assert file_name_base.find(".") < 0
00217     # DEBUG DEBUG DEBUG end
00218 
00219     # First save as PNG.
00220     fig.savefig("%s.png" % file_name_base)
00221 
00222     # Then rescale and reposition the logo (which is assumed to be the
00223     # only artist in the first pair of axes) and save as PDF.
00224     tmp_annbox = fig.axes[0].artists[0]
00225     tmp_offsetbox = tmp_annbox.offsetbox
00226     fig_dpi = fig.dpi
00227     tmp_offsetbox.set_zoom(tmp_offsetbox.get_zoom() * 72. / fig_dpi)
00228     tmp = tmp_annbox.xytext
00229     tmp_annbox.xytext = (tmp[0] + 1., tmp[1] - 1.)
00230     fig.savefig("%s.pdf" % file_name_base, dpi=600)
00231 
00232     # End of SavePlot().


Variable Documentation

tuple public_plots_tools::FONT_PROPS_AX_TITLE = FontProperties(size="x-large", weight="bold")

Definition at line 21 of file public_plots_tools.py.

tuple public_plots_tools::FONT_PROPS_SUPTITLE = FontProperties(size="x-large", weight="bold", stretch="condensed")

Definition at line 19 of file public_plots_tools.py.

tuple public_plots_tools::FONT_PROPS_TICK_LABEL = FontProperties(size="large", weight="bold")

Definition at line 22 of file public_plots_tools.py.

tuple public_plots_tools::FONT_PROPS_TITLE = FontProperties(size="large", weight="regular")

Definition at line 20 of file public_plots_tools.py.