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 40 of file public_plots_tools.py.

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

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().
58 
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 98 of file public_plots_tools.py.

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
108 
def DarkenColor(color_in)
def public_plots_tools.InitMatplotlib ( )
Just some Matplotlib settings.

Definition at line 27 of file public_plots_tools.py.

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().
37 
def public_plots_tools.LatexifyUnits (   units_in)

Definition at line 74 of file public_plots_tools.py.

Referenced by create_public_lumi_plots.PlotAllYears().

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
95 
def LatexifyUnits(units_in)
def public_plots_tools.RoundAwayFromZero (   val)

Definition at line 61 of file public_plots_tools.py.

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
71 
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 22 of file public_plots_tools.py.

public_plots_tools.FONT_PROPS_SUPTITLE

Definition at line 20 of file public_plots_tools.py.

public_plots_tools.FONT_PROPS_TICK_LABEL

Definition at line 23 of file public_plots_tools.py.

public_plots_tools.FONT_PROPS_TITLE

Definition at line 21 of file public_plots_tools.py.

public_plots_tools.size

Definition at line 20 of file public_plots_tools.py.

public_plots_tools.stretch

Definition at line 20 of file public_plots_tools.py.

public_plots_tools.weight

Definition at line 20 of file public_plots_tools.py.