Skip to content

Commit

Permalink
Update corner hist2d to match axis background color (#196)
Browse files Browse the repository at this point in the history
* Update corner hist2d to match axis background color

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update default color to match axes

Default line color now matches axes 'edgecolor' instead of being set to 'black'.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update corner.py

Change default color from black ('k') to None.

* Update arviz_corner.py

Change default color from black ('k') to None.

* Update core.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added hist2d tests for color match

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update default linecolor to ytick color

* Update hist2d tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
delinea and pre-commit-ci[bot] committed Jun 7, 2022
1 parent a281b66 commit d168d67
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/corner/arviz_corner.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def arviz_corner(
# Original corner parameters
range=None,
weights=None,
color="k",
color=None,
hist_bin_factor=1,
smooth=None,
smooth1d=None,
Expand Down
20 changes: 14 additions & 6 deletions src/corner/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import copy
import logging

import matplotlib
import numpy as np
from matplotlib import pyplot as pl
from matplotlib.colors import LinearSegmentedColormap, colorConverter
Expand All @@ -27,7 +28,7 @@ def corner_impl(
bins=20,
range=None,
weights=None,
color="k",
color=None,
hist_bin_factor=1,
smooth=None,
smooth1d=None,
Expand Down Expand Up @@ -171,6 +172,10 @@ def corner_impl(
"Dimension mismatch between hist_bin_factor and " "range"
)

# Set up the default plotting arguments.
if color is None:
color = matplotlib.rcParams["ytick.color"]

# Set up the default histogram keywords.
if hist_kwargs is None:
hist_kwargs = dict()
Expand Down Expand Up @@ -545,21 +550,24 @@ def hist2d(

# Set up the default plotting arguments.
if color is None:
color = "k"
color = matplotlib.rcParams["ytick.color"]

# Choose the default "sigma" contour levels.
if levels is None:
levels = 1.0 - np.exp(-0.5 * np.arange(0.5, 2.1, 0.5) ** 2)

# This is the base color of the axis (background color)
base_color = ax.get_facecolor()

# This is the color map for the density plot, over-plotted to indicate the
# density of the points near the center.
density_cmap = LinearSegmentedColormap.from_list(
"density_cmap", [color, (1, 1, 1, 0)]
"density_cmap", [color, colorConverter.to_rgba(base_color, alpha=0.0)]
)

# This color map is used to hide the points at the high density areas.
white_cmap = LinearSegmentedColormap.from_list(
"white_cmap", [(1, 1, 1), (1, 1, 1)], N=2
base_cmap = LinearSegmentedColormap.from_list(
"base_cmap", [base_color, base_color], N=2
)

# This "color map" is the list of colors for the contour levels if the
Expand Down Expand Up @@ -662,7 +670,7 @@ def hist2d(
Y2,
H2.T,
[V.min(), H.max()],
cmap=white_cmap,
cmap=base_cmap,
antialiased=False,
)

Expand Down
2 changes: 1 addition & 1 deletion src/corner/corner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def corner(
# Original corner parameters
range=None,
weights=None,
color="k",
color=None,
hist_bin_factor=1,
smooth=None,
smooth1d=None,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions tests/test_hist2d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import matplotlib
import numpy as np
import pytest
from matplotlib import pyplot as pl
Expand Down Expand Up @@ -60,6 +61,57 @@ def test_color():
_run_hist2d("color", color="g")


@image_comparison(
baseline_images=["backgroundDark"], remove_text=True, extensions=["png"]
)
def test_backgroundDark():
pl.style.use("dark_background")
_run_hist2d("backgroundDark")
pl.style.use("default")


@image_comparison(
baseline_images=["backgroundDark2"], remove_text=True, extensions=["png"]
)
def test_backgroundDark2():
pl.style.use("dark_background")
_run_hist2d("backgroundDark2", color="r")
pl.style.use("default")


@image_comparison(
baseline_images=["backgroundSolarized"],
remove_text=True,
extensions=["png"],
)
def test_backgroundSolarized():
pl.style.use("Solarize_Light2")
_run_hist2d("backgroundSolarized")
pl.style.use("default")


@image_comparison(
baseline_images=["backgroundSeaborn"], remove_text=True, extensions=["png"]
)
def test_backgroundSeaborn():
pl.style.use("seaborn")
_run_hist2d("backgroundSeaborn")
pl.style.use("default")


@image_comparison(
baseline_images=["backgroundColor"], remove_text=True, extensions=["png"]
)
def test_backgroundColor():
pl.style.use("default")
matplotlib.rcParams["axes.facecolor"] = "yellow"
matplotlib.rcParams["axes.edgecolor"] = "red"
matplotlib.rcParams["xtick.color"] = "green"
matplotlib.rcParams["ytick.color"] = "blue"
_run_hist2d("backgroundColor")
pl.style.use("default")


@image_comparison(
baseline_images=["levels1"], remove_text=True, extensions=["png"]
)
Expand Down

0 comments on commit d168d67

Please sign in to comment.