Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions example_1D_posterior_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import gambit_plotting_tools.gambit_plot_utils as plot_utils
import gambit_plotting_tools.gambit_plot_settings as gambit_plot_settings
from gambit_plotting_tools.annotate import add_gambit_header
from gambit_plotting_tools.gambit_colormaps import register_cmaps


# Set styling
register_cmaps()
plt.style.use(['gambit_plotting_tools.gambit', 'gambit_plotting_tools.light'])

#
# Read file
#
Expand Down Expand Up @@ -63,7 +68,6 @@
fig, ax = plot_utils.plot_1D_posterior(
data[x_key],
data[posterior_weights_key],
x_label,
x_bins,
x_bounds=x_bounds,
credible_regions=credible_regions,
Expand All @@ -74,8 +78,12 @@
plot_settings=plot_settings,
)

# Set limits and labels
ax.set_xlim(*x_bounds)
ax.set_xlabel(x_label)

# Add text
fig.text(0.53, 0.85, "Example text", ha="left", va="center", fontsize=plot_settings["fontsize"], color="black")
fig.text(0.53, 0.85, "Example text", ha="left", va="center")

# Add header
add_gambit_header(ax=ax, version="2.5")
Expand Down
13 changes: 11 additions & 2 deletions example_1D_profile_like_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import gambit_plotting_tools.gambit_plot_utils as plot_utils
import gambit_plotting_tools.gambit_plot_settings as gambit_plot_settings
from gambit_plotting_tools.annotate import add_gambit_header, add_gambit_logo
from gambit_plotting_tools.gambit_colormaps import register_cmaps


# Set styling
register_cmaps()
plt.style.use(['gambit_plotting_tools.gambit', 'gambit_plotting_tools.light'])

#
# Read file
Expand Down Expand Up @@ -60,7 +66,6 @@
fig, ax = plot_utils.plot_1D_profile(
data[x_key],
data[y_key],
x_label,
x_bins,
x_bounds=x_bounds,
y_is_loglike=True,
Expand All @@ -73,8 +78,12 @@
plot_settings=plot_settings,
)

# Set limits and labels
ax.set_xlim(*x_bounds)
ax.set_xlabel(x_label)

# Add text
fig.text(0.53, 0.85, "Example text", ha="left", va="center", fontsize=plot_settings["fontsize"], color="black")
fig.text(0.53, 0.85, "Example text", ha="left", va="center")

# Add branding
add_gambit_header(ax=ax, version="2.5")
Expand Down
20 changes: 15 additions & 5 deletions example_2D_posterior_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
import gambit_plotting_tools.gambit_plot_utils as plot_utils
import gambit_plotting_tools.gambit_plot_settings as gambit_plot_settings
from gambit_plotting_tools.annotate import add_header
from gambit_plotting_tools.gambit_colormaps import register_cmaps


# Set styling
register_cmaps()
plt.style.use(['gambit_plotting_tools.gambit', 'gambit_plotting_tools.light'])

#
# Read file
#
Expand Down Expand Up @@ -67,14 +72,12 @@
# If a pretty plot label is not given, just use the key
x_label = plot_labels.get(x_key, x_key)
y_label = plot_labels.get(y_key, y_key)
labels = (x_label, y_label)

# Create 2D posterior figure
fig, ax, cbar_ax = plot_utils.plot_2D_posterior(
data[x_key],
data[y_key],
data[posterior_weights_key],
labels,
xy_bins,
xy_bounds=xy_bounds,
credible_regions=credible_regions,
Expand All @@ -84,16 +87,23 @@
plot_settings=plot_settings,
)

# Set limits and labels
ax.set_xlim(*x_bounds)
ax.set_ylim(*y_bounds)

ax.set_xlabel(x_label)
ax.set_ylabel(y_label)

# Add text
fig.text(0.50, 0.30, "Example text", ha="left", va="center", fontsize=plot_settings["fontsize"], color="white")
fig.text(0.50, 0.30, "Example text", ha="left", va="center")

# Add header
header_text = "$1\\sigma$ and $2\\sigma$ credible regions. \\textsf{GAMBIT} 2.5"
add_header(header_text, ax=ax)

# Add anything else to the plot, e.g. some more lines and labels and stuff
ax.plot([20.0, 30.0], [5.0, 3.0], color="white", linewidth=plot_settings["contour_linewidth"], linestyle="dashed")
fig.text(0.53, 0.79, "A very important line!", ha="left", va="center", rotation=-31.5, fontsize=plot_settings["fontsize"]-5, color="white")
ax.plot([20.0, 30.0], [5.0, 3.0], linestyle="dashed")
fig.text(0.53, 0.79, "A very important line!", ha="left", va="center", rotation=-31.5)

# Add a star marker at the maximum likelihood point
max_like_index = np.argmax(data["LogLike"])
Expand Down
25 changes: 18 additions & 7 deletions example_2D_profile_like_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
import gambit_plotting_tools.gambit_plot_utils as plot_utils
import gambit_plotting_tools.gambit_plot_settings as gambit_plot_settings
from gambit_plotting_tools.annotate import add_header
from gambit_plotting_tools.gambit_colormaps import register_cmaps


# Set styling
register_cmaps()
plt.style.use(['gambit_plotting_tools.gambit', 'gambit_plotting_tools.dark'])

#
# Read data file
#
Expand Down Expand Up @@ -60,22 +65,21 @@

# Load default plot settings and make some adjustments
plot_settings = deepcopy(gambit_plot_settings.plot_settings)
plot_settings["colormap"] = matplotlib.colormaps["plasma"]
plot_settings["interpolation"] = "none"

# If variable bounds are not specified, use the full range from the data
x_bounds = dataset_bounds.get(x_key, [np.min(data[x_key]), np.max(data[x_key])])
y_bounds = dataset_bounds.get(y_key, [np.min(data[y_key]), np.max(data[y_key])])
xy_bounds = (x_bounds, y_bounds)

labels = (plot_labels[x_key], plot_labels[y_key], plot_labels[z_key])
# If a pretty plot label is not given, just use the key
x_label = plot_labels.get(x_key, x_key)
y_label = plot_labels.get(y_key, y_key)

# Create 2D profile likelihood figure
fig, ax, cbar_ax = plot_utils.plot_2D_profile(
data[x_key],
data[y_key],
data[z_key],
labels,
xy_bins,
xy_bounds=xy_bounds,
z_is_loglike=True,
Expand All @@ -86,16 +90,23 @@
plot_settings=plot_settings,
)

# Set limits and labels
ax.set_xlim(*x_bounds)
ax.set_ylim(*y_bounds)

ax.set_xlabel(x_label)
ax.set_ylabel(y_label)

# Add text
fig.text(0.27, 0.83, "Example text", ha="left", va="center", fontsize=plot_settings["fontsize"], color="white")
fig.text(0.27, 0.83, "Example text", ha="left", va="center",)

# Add header
header_text = "$1\\sigma$ and $2\\sigma$ CL regions. \\textsf{GAMBIT} 2.5"
add_header(header_text, ax=ax)

# Add anything else to the plot, e.g. some more lines and labels and stuff
ax.plot([0.0, 1.0], [0.0, 1.0], color="white", linewidth=plot_settings["contour_linewidth"], linestyle="dashed")
fig.text(0.25, 0.35, "A very important line!", ha="left", va="center", rotation=59.5, fontsize=plot_settings["fontsize"]-5, color="white")
ax.plot([0.0, 1.0], [0.0, 1.0], linestyle="dashed")
fig.text(0.25, 0.35, "A very important line!", ha="left", va="center", rotation=59.5, fontsize="x-small")

# Save to file
output_path = f"./plots/2D_profile__{x_key}__{y_key}__{z_key}.pdf"
Expand Down
25 changes: 17 additions & 8 deletions example_2D_profile_like_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import gambit_plotting_tools.gambit_plot_utils as plot_utils
import gambit_plotting_tools.gambit_plot_settings as gambit_plot_settings
from gambit_plotting_tools.annotate import add_header
from gambit_plotting_tools.gambit_colormaps import register_cmaps


# Set styling
register_cmaps()
plt.style.use(['gambit_plotting_tools.gambit', 'gambit_plotting_tools.dark'])

#
# Read file
#
Expand Down Expand Up @@ -64,41 +69,45 @@
# If a pretty plot label is not given, just use the key
x_label = plot_labels.get(x_key, x_key)
y_label = plot_labels.get(y_key, y_key)
z_label = plot_labels.get(z_key, z_key)
labels = (x_label, y_label, z_label)

# Create 2D profile likelihood figure
fig, ax, cbar_ax = plot_utils.plot_2D_profile(
data[x_key],
data[y_key],
data[z_key],
labels,
xy_bins,
xy_bounds=xy_bounds,
z_is_loglike=True,
plot_likelihood_ratio=True,
contour_levels=likelihood_ratio_contour_values,
contour_coordinates_output_file=f"./plots/2D_profile__{x_key}__{y_key}__{z_key}__coordinates.csv",
#contour_coordinates_output_file=f"./plots/2D_profile__{x_key}__{y_key}__{z_key}__coordinates.csv",
z_fill_value = -1*np.finfo(float).max,
add_max_likelihood_marker = True,
plot_settings=plot_settings,
)

# Set limits and labels
ax.set_xlim(*x_bounds)
ax.set_ylim(*y_bounds)

ax.set_xlabel(x_label)
ax.set_ylabel(y_label)

# Add text
fig.text(0.525, 0.350, "Example text", ha="left", va="center", fontsize=plot_settings["fontsize"], color="white")
fig.text(0.525, 0.350, "Example text", ha="left", va="center")

# Add header
header_text = "$1\\sigma$ and $2\\sigma$ CL regions. \\textsf{GAMBIT} 2.5"
add_header(header_text, ax=ax)

# Add anything else to the plot, e.g. some more lines and labels and stuff
ax.plot([20.0, 30.0], [5.0, 3.0], color="white", linewidth=plot_settings["contour_linewidth"], linestyle="dashed")
fig.text(0.53, 0.79, "A very important line!", ha="left", va="center", rotation=-31.5, fontsize=plot_settings["fontsize"]-5, color="white")
ax.plot([20.0, 30.0], [5.0, 3.0], linestyle="dashed")
fig.text(0.53, 0.79, "A very important line!", ha="left", va="center", rotation=-31.5, fontsize="x-small")

# Draw a contour using coordinates stored in a .csv file
x_contour, y_contour = np.loadtxt("./example_data/contour_coordinates.csv", delimiter=",", usecols=(0, 1), unpack=True)
ax.plot(x_contour, y_contour, color="orange", linestyle="dashed", linewidth=plot_settings["contour_linewidth"], alpha=0.7)
fig.text(0.23, 0.23, "Overlaid contour from\n coordinates in some data file", ha="left", va="center", fontsize=plot_settings["fontsize"]-5, color="orange")
fig.text(0.23, 0.23, "Overlaid contour from\n coordinates in some data file", ha="left", va="center", fontsize="x-small", color="orange")

# Save to file
output_path = f"./plots/2D_profile__{x_key}__{y_key}__{z_key}.pdf"
Expand Down
5 changes: 5 additions & 0 deletions example_2D_profile_like_hdf5_multiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import gambit_plotting_tools.gambit_plot_utils as plot_utils
import gambit_plotting_tools.gambit_plot_settings as gambit_plot_settings
from gambit_plotting_tools.annotate import add_header
from gambit_plotting_tools.gambit_colormaps import register_cmaps


# Set styling
register_cmaps()
plt.style.use(['gambit_plotting_tools.gambit', 'gambit_plotting_tools.dark'])

#
# Read files
#
Expand Down
15 changes: 12 additions & 3 deletions example_gambit_light_2D_profile_like_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import gambit_plotting_tools.gambit_plot_utils as plot_utils
import gambit_plotting_tools.gambit_plot_settings as gambit_plot_settings
from gambit_plotting_tools.annotate import add_header
from gambit_plotting_tools.gambit_colormaps import register_cmaps


# Set styling
register_cmaps()
plt.style.use(['gambit_plotting_tools.gambit', 'gambit_plotting_tools.dark'])

#
# Read file
#
Expand Down Expand Up @@ -64,15 +69,12 @@
# If a pretty plot label is not given, just use the key
x_label = plot_labels.get(x_key, x_key)
y_label = plot_labels.get(y_key, y_key)
z_label = plot_labels.get(z_key, z_key)
labels = (x_label, y_label, z_label)

# Create 2D profile likelihood figure
fig, ax, cbar_ax = plot_utils.plot_2D_profile(
data[x_key],
data[y_key],
data[z_key],
labels,
xy_bins,
xy_bounds=xy_bounds,
z_is_loglike=True,
Expand All @@ -83,6 +85,13 @@
plot_settings=plot_settings,
)

# Set limits and labels
ax.set_xlim(*x_bounds)
ax.set_ylim(*y_bounds)

ax.set_xlabel(x_label)
ax.set_ylabel(y_label)

# Add header
header_text = "$1\\sigma$ and $2\\sigma$ CL regions."
add_header(header_text, ax=ax)
Expand Down
26 changes: 12 additions & 14 deletions gambit_plotting_tools/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,37 @@
=======================
"""

import importlib.resources

import matplotlib.pyplot as plt
import PIL
import numpy as np
import importlib.resources

from gambit_plotting_tools.gambit_plot_settings import plot_settings


def add_header(header_text, ax=None, fontsize=plot_settings["header_fontsize"]):
def add_header(header_text, ax=None, pad=2):
if ax is None:
ax = plt.gca()
ax.set_title(
header_text,
loc="right",
pad=plot_settings["header_pad"],
fontsize=fontsize)
header_text,
loc="right",
pad=pad)


def add_gambit_header(ax=None, version=None, fontsize=plot_settings["header_fontsize"]):
def add_gambit_header(ax=None, version=None, **kwargs):
if version is not None:
header_text = f"\\textsf{{GAMBIT {version}}}"
else:
header_text = "\\textsf{GAMBIT}"
add_header(header_text, fontsize=fontsize)
add_header(header_text, ax, **kwargs)


def load_small_gambit_logo():
im = PIL.Image.open(importlib.resources.path('gambit_plotting_tools', 'gambit_logo_small.png'))
im = np.array(im)
return im
with importlib.resources.path('gambit_plotting_tools', 'gambit_logo_small.png') as file_name:
im = PIL.Image.open(file_name)
return np.array(im)


def add_gambit_logo(ax=None, zorder=3, size=plot_settings["logo_size"]):
def add_gambit_logo(ax=None, zorder=3, size=0.27):
if ax is None:
ax = plt.gca()
inset = ax.inset_axes([1.0 - size, 0.0, size, size], zorder=zorder)
Expand Down
12 changes: 12 additions & 0 deletions gambit_plotting_tools/cbar.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
font.size: 11

axes.edgecolor: black
axes.labelpad: 18

xtick.color: black
ytick.color: black

xtick.major.pad: 2
xtick.minor.pad: 2
ytick.major.pad: 2
ytick.minor.pad: 2
13 changes: 13 additions & 0 deletions gambit_plotting_tools/dark.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
xtick.color: white
ytick.color: white
xtick.labelcolor: black
ytick.labelcolor: black

axes.labelcolor: black
axes.facecolor: 0.5
axes.edgecolor: white

image.cmap: gambit-dark

lines.color: white
text.color: white
Loading