Skip to content

Commit

Permalink
Merge pull request #393 from hakonanes/fix-380
Browse files Browse the repository at this point in the history
Allow to pass c/color and s/sizes to StereographicPlot.scatter()
  • Loading branch information
hakonanes authored Sep 30, 2022
2 parents 525cb9c + 9e38674 commit d30a9a8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ All notable changes to the ``orix`` project are documented in this file.
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_, and
this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

2022-09-30 - version 0.10.1
===========================

Fixed
-----
- ``StereographicPlot.scatter()`` now accepts both ``c``/``color`` and ``s``/``sizes``
to set the color and sizes of scatter points, in line with
``matplotlib.axes.Axes.scatter()``.

2022-09-22 - version 0.10.0
===========================

Expand Down
22 changes: 16 additions & 6 deletions orix/plot/stereographic_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,20 @@ def scatter(
if x.size == 0:
return

# Color(s) and size(s)
c = updated_kwargs.pop("c", "C0")
# Color(s)
if "color" in updated_kwargs.keys():
key_color = "color"
else:
key_color = "c"
c = updated_kwargs.pop(key_color, "C0")
c = _get_array_of_values(value=c, visible=visible)
s = updated_kwargs.pop("s", None)

# Size(s)
if "sizes" in updated_kwargs.keys():
key_size = "sizes"
else:
key_size = "s"
s = updated_kwargs.pop(key_size, None)
if s is not None:
s = _get_array_of_values(value=s, visible=visible)

Expand Down Expand Up @@ -333,8 +343,6 @@ def pole_density_function(
sigma=sigma,
log=log,
hemisphere=self.hemisphere,
symmetry=None,
mrd=True,
weights=weights,
)

Expand Down Expand Up @@ -758,7 +766,9 @@ def _prepare_to_call_inherited_method(
return x, y, visible, updated_kwargs

def _pretransform_input(
self, values: Union[Vector3d, Tuple[np.ndarray, np.ndarray]], sort: bool = False
self,
values: Union[Vector3d, Tuple[Vector3d], Tuple[np.ndarray, np.ndarray]],
sort: bool = False,
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
"""Return arrays of (x, y) from input data.
Expand Down
24 changes: 24 additions & 0 deletions orix/tests/plot/test_stereographic_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,30 @@ def test_order_in_hemisphere(self):

plt.close("all")

def test_color_parameter(self):
"""Pass either ``color`` or ``c`` to color scatter points."""
v = Vector3d([[1, 0, 0], [1, 1, 0], [1, 1, 1]])

colors = [f"C{i}" for i in range(v.size)]
colors_rgba = np.array([mcolors.to_rgba(c) for c in colors])

fig = v.scatter(color=colors, return_figure=True)
assert np.allclose(fig.axes[0].collections[0].get_facecolors(), colors_rgba)

fig2 = v.scatter(c=colors, return_figure=True)
assert np.allclose(fig2.axes[0].collections[0].get_facecolors(), colors_rgba)

def test_size_parameter(self):
"""Pass either ``sizes`` or ``s`` to set scatter points sizes."""
v = Vector3d([[1, 0, 0], [1, 1, 0], [1, 1, 1]])
sizes = np.arange(v.size)

fig = v.scatter(sizes=sizes, return_figure=True)
assert np.allclose(fig.axes[0].collections[0].get_sizes(), sizes)

fig2 = v.scatter(s=sizes, return_figure=True)
assert np.allclose(fig2.axes[0].collections[0].get_sizes(), sizes)


class TestSymmetryMarker:
def test_properties(self):
Expand Down

0 comments on commit d30a9a8

Please sign in to comment.