CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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.

Referenced by create_public_lumi_plots.PlotAllYears(), and create_public_peakpu_plots.PlotPeakPUAllYears().

39 
40 def AddLogo(logo_name, ax, zoom=1.2):
41  """Read logo from PNG file and add it to axes."""
42 
43  logo_data = read_png(logo_name)
44  fig_dpi = ax.get_figure().dpi
45  fig_size = ax.get_figure().get_size_inches()
46  # NOTE: This scaling is kinda ad hoc...
47  zoom_factor = .1 / 1.2 * fig_dpi * fig_size[0] / np.shape(logo_data)[0]
48  zoom_factor *= zoom
49  logo_box = OffsetImage(logo_data, zoom=zoom_factor)
50  ann_box = AnnotationBbox(logo_box, [0., 1.],
51  xybox=(2., -3.),
52  xycoords="axes fraction",
53  boxcoords="offset points",
54  box_alignment=(0., 1.),
55  pad=0., frameon=False)
56  ax.add_artist(ann_box)
57  # 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.

97 
98 def DarkenColor(color_in):
99  """Takes a tuple (r, g, b) as input."""
100 
101  color_tmp = matplotlib.colors.colorConverter.to_rgb(color_in)
102 
103  tmp = rgb_to_hls(*color_tmp)
104  color_out = hls_to_rgb(tmp[0], .7 * tmp[1], tmp[2])
105 
106  # End of DarkenColor().
107  return color_out
def public_plots_tools.InitMatplotlib ( )
Just some Matplotlib settings.

Definition at line 26 of file public_plots_tools.py.

26 
27 def InitMatplotlib():
28  """Just some Matplotlib settings."""
29  matplotlib.rcParams["text.usetex"] = False
30  matplotlib.rcParams["legend.numpoints"] = 1
31  matplotlib.rcParams["figure.figsize"] = (8., 6.)
32  matplotlib.rcParams["figure.dpi"] = 300
33  matplotlib.rcParams["savefig.dpi"] = matplotlib.rcParams["figure.dpi"]
34  matplotlib.rcParams["font.size"] = 10.8
35  matplotlib.rcParams["pdf.fonttype"] = 42
36  # End of InitMatplotlib().
def public_plots_tools.LatexifyUnits (   units_in)

Definition at line 73 of file public_plots_tools.py.

Referenced by create_public_lumi_plots.PlotAllYears().

73 
74 def LatexifyUnits(units_in):
75 
76  latex_units = {
77  "b^{-1}" : "$\mathbf{b}^{-1}$",
78  "mb^{-1}" : "$\mathbf{mb}^{-1}$",
79  "ub^{-1}" : "$\mu\mathbf{b}^{-1}$",
80  "nb^{-1}" : "$\mathbf{nb}^{-1}$",
81  "pb^{-1}" : "$\mathbf{pb}^{-1}$",
82  "fb^{-1}" : "$\mathbf{fb}^{-1}$",
83  "Hz/b" : "$\mathbf{Hz/b}$",
84  "Hz/mb" : "$\mathbf{Hz/mb}$",
85  "Hz/ub" : "$\mathbf{Hz/}\mathbf{\mu}\mathbf{b}$",
86  "Hz/nb" : "$\mathbf{Hz/nb}$",
87  "Hz/pb" : "$\mathbf{Hz/pb}$",
88  "Hz/fb" : "$\mathbf{Hz/fb}$"
89  }
90 
91  res = latex_units[units_in]
92 
93  # End of LatexifyUnits().
94  return res
def public_plots_tools.RoundAwayFromZero (   val)

Definition at line 60 of file public_plots_tools.py.

60 
61 def RoundAwayFromZero(val):
62 
63  res = None
64  if val < 0.:
65  res = math.floor(val)
66  else:
67  res = math.ceil(val)
68 
69  # End of RoundAwayFromZero().
70  return res
def public_plots_tools.SavePlot (   fig,
  file_name_base 
)
Little helper to save plots in various formats.

Definition at line 215 of file public_plots_tools.py.

Referenced by create_public_lumi_plots.PlotAllYears(), and create_public_peakpu_plots.PlotPeakPUAllYears().

216 def SavePlot(fig, file_name_base):
217  """Little helper to save plots in various formats."""
218 
219  # DEBUG DEBUG DEBUG
220  # Check some assumptions.
221  assert len(fig.axes) == 2
222  assert len(fig.axes[0].artists) == 1
223  assert file_name_base.find(".") < 0
224  # DEBUG DEBUG DEBUG end
225 
226  # First save as PNG.
227  fig.savefig("%s.png" % file_name_base)
228 
229  # Then rescale and reposition the logo (which is assumed to be the
230  # only artist in the first pair of axes) and save as PDF.
231  tmp_annbox = fig.axes[0].artists[0]
232  tmp_offsetbox = tmp_annbox.offsetbox
233  fig_dpi = fig.dpi
234  tmp_offsetbox.set_zoom(tmp_offsetbox.get_zoom() * 72. / fig_dpi)
235  tmp = tmp_annbox.xytext
236  tmp_annbox.xytext = (tmp[0] + 1., tmp[1] - 1.)
237  fig.savefig("%s.pdf" % file_name_base, dpi=600)
238 
239  # 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.