ATLAS Offline Software
plotlib.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 
4 #***************************************************************************
5 # plotlib.py -
6 # -------------------
7 # begin : 28 03 2020
8 # email : tong.qiu@cern.ch
9 # **************************************************************************
10 import matplotlib
11 matplotlib.use('Agg')
12 import math
13 import matplotlib.pyplot as plt
14 import numpy as np
15 import copy
16 
17 def histplot(data_x, data_y, error=None, label=None, **kwargs):
18  settings = {
19  "xlabel" : r"$p_T\:[GeV]$",
20  "ylabel": 'Efficiency',
21  "title1": r"ATLAS",
22  "title1_1": r"Simulation",
23  "title2": r"$\sqrt{s}=13\:TeV$",
24  "filename": "trunontest",
25  "log_y":False,
26  "norm":False,
27  "scale":1,
28  "upper_y": 1.7,
29  "errorbar_limit": None,
30  }
31  for each_key in kwargs.items():
32  settings[each_key[0]] = kwargs[each_key[0]]
33  plt.figure(figsize=(8, 6))
34  remove_label = False
35  if label is None:
36  remove_label = True
37  label = ["a"] * len(data_x)
38  for i in range(len(data_x)):
39  if error is not None:
40  if settings["errorbar_limit"] is not None:
41  allerror = []
42  for each_error, each_yi in zip(error[i], data_y[i]):
43  uperror = each_error
44  if each_yi + each_error > settings["errorbar_limit"]:
45  uperror = settings["errorbar_limit"] - each_yi
46  allerror.append([each_error, uperror])
47  else:
48  allerror = error[i]
49  style = '.-'
50  if len(data_x) == 1:
51  style = 'k.-'
52  plt.errorbar(data_x[i], data_y[i], yerr=np.array(allerror).T, label=label[i], fmt=style)
53  else:
54  plt.plot(data_x[i], data_y[i], label=label[i])
55  ax1 = plt.gca()
56 
57  plt.legend(loc='upper right', prop={'size': 25}, frameon=False)
58  if remove_label:
59  ax1.get_legend().remove()
60 
61  ax1.set_ylim([0, max([y for x in data_y for y in x])* settings["upper_y"]])
62  ax1.text(0.05, 1.55 / 1.7, settings['title1'], fontsize=25, transform=ax1.transAxes, style='italic', fontweight='bold')
63  ax1.text(0.28, 1.55/ 1.7, settings['title1_1'], fontsize=25, transform=ax1.transAxes)
64  ax1.text(0.05, 1.40 / 1.7, settings['title2'], fontsize=23, transform=ax1.transAxes)
65 
66  plt.tick_params(labelsize=16)
67  plt.tick_params(labelsize=16)
68  plt.ylabel(settings['ylabel'], fontsize=20)
69  plt.xlabel(settings['xlabel'], fontsize=20)
70  plt.savefig(settings['filename'] + '.pdf', bbox_inches='tight')
71  plt.close()
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
plotlib.histplot
def histplot(data_x, data_y, error=None, label=None, **kwargs)
Definition: plotlib.py:17