matplotlib

2021
python matplotlib

Table of Contents


How to plot

import matplotlib.pyplot as plt
plt.hist("VariableName", bins=100, range=(0, 1550), label=var_plots,alpha=0.6)
plt.xlabel("VariableName")
plt.ylabel('Number of events')
plt.yscale('log')
plt.legend()
plt.ioff() # to turn off the displaying plots.
# plt.show()
plt.savefig('VariableName.png')
plt.savefig('VariableName.pdf')
plt.close()

Difference between clf(), cla(), and close()

  • plt.cla(): clears an axes, i.e. the currently active axes in the current figure. It leaves the other axes untouched.
  • plt.clf(): clears the entire current figure with all its axes, but leaves the window opened, such that it may be reused for other plots.
  • plt.close(): closes a window, which will be the current window, if not specified otherwise.

Reference: https://stackoverflow.com/a/8228808/2302094




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Effective Field Theory (EFT) in High Energy Physics
  • CMS Full Detector Simulations based on mccm chain
  • Physics Words and Concepts
  • Macbook Keynote Tricks
  • Scalar search in CMS
  • HH Analysis in CMS
  • dasgoclient
  • fc command
  • CMS Software (CMSSW)
  • CMS HEM Issue