From 030375250a898f73999e603332fce344056256d3 Mon Sep 17 00:00:00 2001 From: kreczko Date: Wed, 18 Feb 2015 11:51:05 +0000 Subject: [PATCH 1/2] making dynamic tick placement always include 1 (if in range) --- tools/plotting.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tools/plotting.py b/tools/plotting.py index 5a17c1aa..98180bf9 100644 --- a/tools/plotting.py +++ b/tools/plotting.py @@ -13,7 +13,7 @@ from matplotlib.patches import Rectangle from copy import deepcopy import matplotlib.gridspec as gridspec -from matplotlib.ticker import MultipleLocator +from matplotlib.ticker import MultipleLocator, FixedLocator from itertools import cycle from matplotlib import rc @@ -194,13 +194,7 @@ def make_data_mc_comparison_plot( histograms = [], ymax = histogram_properties.ratio_y_limits[1] ) # dynamic tick placement - ticks = ax1.yaxis.get_ticklocs() - tick_min, tick_max = ticks[0], ticks[-1] - # limit to 3 ticks - tick_distance = abs(tick_max - tick_min)/4 - ax1.yaxis.set_major_locator( MultipleLocator( tick_distance ) ) - ax1.yaxis.set_minor_locator( MultipleLocator( tick_distance/2 ) ) - + adjust_ratio_ticks(ax1.yaxis, n_ticks = 3) if CMS.tight_layout: plt.tight_layout() @@ -265,8 +259,8 @@ def make_control_region_comparison( control_region_1, control_region_2, ax1 = plt.subplot( gs[1] ) ax1.minorticks_on() ax1.grid( True, 'major', linewidth = 1 ) - ax1.yaxis.set_major_locator( MultipleLocator( 1.0 ) ) - ax1.yaxis.set_minor_locator( MultipleLocator( 0.5 ) ) + # dynamic tick placement + adjust_ratio_ticks(ax1.yaxis, n_ticks = 3) set_labels( plt, histogram_properties, show_x_label = True, show_title = False ) plt.ylabel( '(1)/(2)', CMS.y_axis_title ) rplt.errorbar( ratio, xerr = True, emptybins = False, axes = ax1 ) @@ -377,12 +371,7 @@ def make_shape_comparison_plot( shapes = [], ax1.set_ylim( ymin = histogram_properties.ratio_y_limits[0], ymax = histogram_properties.ratio_y_limits[1] ) # dynamic tick placement - ticks = ax1.yaxis.get_ticklocs() - tick_min, tick_max = ticks[0], ticks[-1] - # limit to 3 ticks - tick_distance = abs(tick_max - tick_min)/4 - ax1.yaxis.set_major_locator( MultipleLocator( tick_distance ) ) - ax1.yaxis.set_minor_locator( MultipleLocator( tick_distance/2 ) ) + adjust_ratio_ticks(ax1.yaxis, n_ticks = 3) if CMS.tight_layout: plt.tight_layout() @@ -563,3 +552,16 @@ def check_save_folder(save_folder): make_folder_if_not_exists(save_folder) return save_folder + +def adjust_ratio_ticks( axis, n_ticks = 3 ): + # dynamic tick placement + ticks = axis.get_ticklocs() + tick_min, tick_max = ticks[0], ticks[-1] + # limit to 3 ticks + tick_distance = abs( tick_max - tick_min ) / ( n_ticks + 1 ) + includes_one = tick_max > 1 and tick_min < 1 + if includes_one: + axis.set_major_locator( FixedLocator( [tick_min + tick_distance/2, 1, tick_max - tick_distance/2] ) ) + else: + axis.set_major_locator( MultipleLocator( tick_distance ) ) + axis.set_minor_locator( MultipleLocator( tick_distance / 2 ) ) From 895ab07c1e95977fb172b07071a69a137724f0df Mon Sep 17 00:00:00 2001 From: kreczko Date: Wed, 18 Feb 2015 11:55:44 +0000 Subject: [PATCH 2/2] updating plotting configs and gitignore --- .gitignore | 3 +- config/plots/MET_7TeV_electron_channel.json | 46 +++++++++++++++++++++ config/plots/MET_8TeV_electron_channel.json | 10 ++--- 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 config/plots/MET_7TeV_electron_channel.json diff --git a/.gitignore b/.gitignore index f27cee7e..f1eb9ba4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,13 +7,14 @@ *.root *.out *.o +*.tar* *~ .DS_Store #data, plots and tables potentially include non-approved data == don't make them public **/data*/* data tables -**/plots*/* +plots*/* **/tables*/* src/cross_section_measurement/data/ src/unfolding_tests/plots/ diff --git a/config/plots/MET_7TeV_electron_channel.json b/config/plots/MET_7TeV_electron_channel.json new file mode 100644 index 00000000..0e91fc90 --- /dev/null +++ b/config/plots/MET_7TeV_electron_channel.json @@ -0,0 +1,46 @@ +{ + "command": "compare-files", + "files": [ + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/7TeV/central/ElectronHad_5050pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/7TeV/central/QCD_Electron_5050pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/7TeV/central/VJets_5050pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/7TeV/central/SingleTop_5050pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/7TeV/central/TTJet_5050pb_PFElectron_PFMuon_PF2PATJets_PFMET.root" + ], + "histograms": [ + "TTbar_plus_X_analysis/EPlusJets/Ref selection/MET/patType1CorrectedPFMet/MET_2orMoreBtags" + ], + "labels": [ + "data", + "QCD", + "W/Z + jets", + "single-top", + "$t\\bar{t}$" + ], + "output_folder": "plots/7TeV", + "output_format": ["png"], + "plot_type": "data_mc_comparison", + "ratio_y_limits": [ + [ + 0.2, + 1.5 + ] + ], + "title": [ + "$E_T^{\\text{miss}}$ at $\\sqrt{s}$ = 7 TeV, e+jets" + ], + "x_axis_title": [ + "$E_T^{\\text{miss}}$ [GeV]" + ], + "x_limits": [ + [ + 0, + 300 + ] + ], + "y_axis_title": [ + "events/5 GeV" + ], + "colours": ["black", "yellow", "green", "magenta", "red"], + "mc_error": [0.15] +} \ No newline at end of file diff --git a/config/plots/MET_8TeV_electron_channel.json b/config/plots/MET_8TeV_electron_channel.json index 3f5c459b..2d0b1cfe 100644 --- a/config/plots/MET_8TeV_electron_channel.json +++ b/config/plots/MET_8TeV_electron_channel.json @@ -1,11 +1,11 @@ { "command": "compare-files", "files": [ - "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_5th_draft/8TeV/central/SingleElectron_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", - "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_5th_draft/8TeV/central/QCD_Electron_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", - "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_5th_draft/8TeV/central/VJets_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", - "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_5th_draft/8TeV/central/SingleTop_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", - "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_5th_draft/8TeV/central/TTJet_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root" + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/8TeV/central/SingleElectron_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/8TeV/central/QCD_Electron_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/8TeV/central/VJets_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/8TeV/central/SingleTop_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root", + "/hdfs/TopQuarkGroup/results/histogramfiles/AN-14-071_6th_draft/8TeV/central/TTJet_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root" ], "histograms": [ "TTbar_plus_X_analysis/EPlusJets/Ref selection/MET/patType1CorrectedPFMet/MET_2orMoreBtags"