Skip to content

Commit

Permalink
Fix to color='C2' plot_2d error post pandas 2 (#382)
Browse files Browse the repository at this point in the history
* Added failing test

* bump version to 2.8.10

* Get color from self.color

* Update README.rst

* Update _version.py

* Update README.rst

* Update _version.py

---------

Co-authored-by: Lukas Hergt <lthergt@posteo.de>
  • Loading branch information
williamjameshandley and lukashergt committed Apr 24, 2024
1 parent bd402c4 commit 8726a90
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
anesthetic: nested sampling post-processing
===========================================
:Authors: Will Handley and Lukas Hergt
:Version: 2.8.11
:Version: 2.8.12
:Homepage: https://github.com/handley-lab/anesthetic
:Documentation: http://anesthetic.readthedocs.io/

Expand Down
2 changes: 1 addition & 1 deletion anesthetic/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.8.11'
__version__ = '2.8.12'
2 changes: 2 additions & 0 deletions anesthetic/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def _make_plot(self, fig):
ax = self._get_ax(0) # another one of these hard-coded 0s

kwds = self.kwds.copy()
if self.color is not None:
kwds["color"] = self.color
label = pprint_thing(self.label)
kwds["label"] = label

Expand Down
32 changes: 15 additions & 17 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,31 +308,29 @@ def test_plot_2d_colours(kind):
kinds = {'diagonal': kind + '_1d',
'lower': kind + '_2d',
'upper': 'scatter_2d'}
gd.plot_2d(axes, kind=kinds, label="gd")
pc.plot_2d(axes, kind=kinds, label="pc")
mn.plot_2d(axes, kind=kinds, label="mn")
gd_colors = []
pc_colors = []
mn_colors = []
gd.plot_2d(axes, kind=kinds, label="A")
pc.plot_2d(axes, kind=kinds, label="B")
mn.plot_2d(axes, kind=kinds, label="C")
gd.plot_2d(axes, kind=kinds, label="D", color='C7')
pc.plot_2d(axes, kind=kinds, label="E", color='C6')
mn.plot_2d(axes, kind=kinds, label="F", color='C5')

from collections import defaultdict
d = defaultdict(set)

for y, rows in axes.iterrows():
for x, ax in rows.items():
handles, labels = ax.get_legend_handles_labels()
for handle, label in zip(handles, labels):
if isinstance(handle, Rectangle):
color = to_hex(handle.get_facecolor())
color = handle.get_facecolor()
else:
color = handle.get_color()
color = to_hex(color)
d[label].add(color)

if label == 'gd':
gd_colors.append(color)
elif label == 'pc':
pc_colors.append(color)
elif label == 'mn':
mn_colors.append(color)

assert len(set(gd_colors)) == 1
assert len(set(mn_colors)) == 1
assert len(set(pc_colors)) == 1
for v in d.values():
assert len(v) == 1


@pytest.mark.parametrize('kwargs', [dict(color='r', alpha=0.5, ls=':', lw=1),
Expand Down

0 comments on commit 8726a90

Please sign in to comment.