CMS 3D CMS Logo

Classes | Functions | Variables
public_plots_tools Namespace Reference

Classes

class  ColorScheme
 

Functions

def AddLogo (logo_name, ax, zoom=1.2)
 
def DarkenColor (color_in)
 
def InitMatplotlib ()
 
def LatexifyUnits (units_in)
 
def RoundAwayFromZero (val)
 
def SavePlot (fig, file_name_base)
 

Variables

 FONT_PROPS_AX_TITLE
 
 FONT_PROPS_SUPTITLE
 
 FONT_PROPS_TICK_LABEL
 
 FONT_PROPS_TITLE
 
 size
 
 stretch
 
 weight
 

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 def AddLogo(logo_name, ax, zoom=1.2):
40  """Read logo from PNG file and add it to axes."""
41 
42  logo_data = read_png(logo_name)
43  fig_dpi = ax.get_figure().dpi
44  fig_size = ax.get_figure().get_size_inches()
45  # NOTE: This scaling is kinda ad hoc...
46  zoom_factor = .1 / 1.2 * fig_dpi * fig_size[0] / np.shape(logo_data)[0]
47  zoom_factor *= zoom
48  logo_box = OffsetImage(logo_data, zoom=zoom_factor)
49  ann_box = AnnotationBbox(logo_box, [0., 1.],
50  xybox=(2., -3.),
51  xycoords="axes fraction",
52  boxcoords="offset points",
53  box_alignment=(0., 1.),
54  pad=0., frameon=False)
55  ax.add_artist(ann_box)
56  # End of AddLogo().
57 
def AddLogo(logo_name, ax, zoom=1.2)
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 def DarkenColor(color_in):
98  """Takes a tuple (r, g, b) as input."""
99 
100  color_tmp = matplotlib.colors.colorConverter.to_rgb(color_in)
101 
102  tmp = rgb_to_hls(*color_tmp)
103  color_out = hls_to_rgb(tmp[0], .7 * tmp[1], tmp[2])
104 
105  # End of DarkenColor().
106  return color_out
107 
def DarkenColor(color_in)
def public_plots_tools.InitMatplotlib ( )
Just some Matplotlib settings.

Definition at line 26 of file public_plots_tools.py.

27  """Just some Matplotlib settings."""
28  matplotlib.rcParams["text.usetex"] = False
29  matplotlib.rcParams["legend.numpoints"] = 1
30  matplotlib.rcParams["figure.figsize"] = (8., 6.)
31  matplotlib.rcParams["figure.dpi"] = 300
32  matplotlib.rcParams["savefig.dpi"] = matplotlib.rcParams["figure.dpi"]
33  matplotlib.rcParams["font.size"] = 10.8
34  matplotlib.rcParams["pdf.fonttype"] = 42
35  # End of InitMatplotlib().
36 
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 def LatexifyUnits(units_in):
74 
75  latex_units = {
76  "b^{-1}" : "$\mathbf{b}^{-1}$",
77  "mb^{-1}" : "$\mathbf{mb}^{-1}$",
78  "ub^{-1}" : "$\mu\mathbf{b}^{-1}$",
79  "nb^{-1}" : "$\mathbf{nb}^{-1}$",
80  "pb^{-1}" : "$\mathbf{pb}^{-1}$",
81  "fb^{-1}" : "$\mathbf{fb}^{-1}$",
82  "Hz/b" : "$\mathbf{Hz/b}$",
83  "Hz/mb" : "$\mathbf{Hz/mb}$",
84  "Hz/ub" : "$\mathbf{Hz/}\mathbf{\mu}\mathbf{b}$",
85  "Hz/nb" : "$\mathbf{Hz/nb}$",
86  "Hz/pb" : "$\mathbf{Hz/pb}$",
87  "Hz/fb" : "$\mathbf{Hz/fb}$"
88  }
89 
90  res = latex_units[units_in]
91 
92  # End of LatexifyUnits().
93  return res
94 
def LatexifyUnits(units_in)
def public_plots_tools.RoundAwayFromZero (   val)

Definition at line 60 of file public_plots_tools.py.

61 
62  res = None
63  if val < 0.:
64  res = math.floor(val)
65  else:
66  res = math.ceil(val)
67 
68  # End of RoundAwayFromZero().
69  return res
70 
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().

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

Variable Documentation

public_plots_tools.FONT_PROPS_AX_TITLE

Definition at line 21 of file public_plots_tools.py.

public_plots_tools.FONT_PROPS_SUPTITLE

Definition at line 19 of file public_plots_tools.py.

public_plots_tools.FONT_PROPS_TICK_LABEL

Definition at line 22 of file public_plots_tools.py.

public_plots_tools.FONT_PROPS_TITLE

Definition at line 20 of file public_plots_tools.py.

public_plots_tools.size

Definition at line 19 of file public_plots_tools.py.

public_plots_tools.stretch

Definition at line 19 of file public_plots_tools.py.

public_plots_tools.weight

Definition at line 19 of file public_plots_tools.py.