Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass c/color and s/sizes to StereographicPlot.scatter() #393

Merged
merged 1 commit into from
Sep 30, 2022
Merged
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
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():
harripj marked this conversation as resolved.
Show resolved Hide resolved
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