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

Using color maps in plot_khat #1592

Merged
merged 8 commits into from
Mar 5, 2021
Merged

Using color maps in plot_khat #1592

merged 8 commits into from
Mar 5, 2021

Conversation

agustinaarroyuelo
Copy link
Contributor

@agustinaarroyuelo agustinaarroyuelo commented Mar 2, 2021

Description

plot_khat can take a c argument to use with a color map

cmaps_khat

Checklist

  • Follows official PR format
  • Includes a sample plot to visually illustrate the changes (only for plot-related functions)
  • Code style correct (follows pylint and black guidelines)
  • Changes are listed in changelog

@OriolAbril
Copy link
Member

Looking now at the code and the comments in slack, does az.plot_khat(loo, color=values) work? I think it should work already with the current rgba_c generation and use a colormap. We may have to handle the presence of the c kwarg better though.

@agustinaarroyuelo
Copy link
Contributor Author

You are right az.plot_khat(loo, color=values) works. Is this PR enough for handling the c kwarg?

@OriolAbril
Copy link
Member

I would have the color argument of plot_khat take preference over the c passed as kwarg, I think we can do that by adding these lines after the dealiaser, around line 78:

c_kwarg = kwargs.pop("c", None)
if c_kwarg is not None:
    warnings.warn("Found kwarg named `c` which will be ignored, use `color` instead")

But I would also understand wanting to pass c to avoid all the preprocessing done to color, ,we could also use the check to instead of printing a warning, use c directly and avoid all the color preprocessing crazyness.

@OriolAbril
Copy link
Member

Oh, the preprocessing is also used to create a legend based on the colors shown if desired in case the variable that gets color encoded is discrete instead of continuous.

@@ -93,6 +93,7 @@ def plot_khat(
rgba_c = to_rgba_array(np.full(n_data_points, color))
else:
legend = False
color = (color - color.min()) / (color.max() - color.min())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to come after the except. At this point color can be a list of strings or a nx3 array of rgb colors. I would also suggest using matplotlib normalizer function in case someone wanted to use a different one

cmap_name = kwargs.get("cmap", plt.rcParams["image.cmap"])
cmap = getattr(cm, cmap_name)
norm_fun = kwargs.get("norm", mpl.colors.Normalize(color.min(), color.max()))
rgba_c = cmap(norm_fun(color))

Comment on lines 109 to 116
else:
if isinstance(c_kwarg, str):
if c_kwarg in dims:
colors, color_mapping = color_from_dim(khats, c_kwarg)
else:
legend = False
else:
legend = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not add that. I think c should always behave exactly like the argument in matplotlb.scatter if they want any of the other features, users should use color

@codecov
Copy link

codecov bot commented Mar 4, 2021

Codecov Report

Merging #1592 (ed4309e) into main (c562fad) will decrease coverage by 0.03%.
The diff coverage is 86.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1592      +/-   ##
==========================================
- Coverage   90.05%   90.02%   -0.04%     
==========================================
  Files         108      108              
  Lines       11584    11594      +10     
==========================================
+ Hits        10432    10437       +5     
- Misses       1152     1157       +5     
Impacted Files Coverage Δ
arviz/plots/backends/matplotlib/khatplot.py 73.07% <83.87%> (-1.93%) ⬇️
arviz/data/base.py 97.87% <100.00%> (ø)
arviz/data/io_pymc3.py 90.68% <100.00%> (ø)
arviz/plots/backends/bokeh/energyplot.py 93.44% <100.00%> (ø)
arviz/plots/backends/matplotlib/energyplot.py 90.00% <100.00%> (ø)
arviz/plots/backends/matplotlib/ppcplot.py 98.07% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c562fad...be47816. Read the comment docs.

@OriolAbril OriolAbril merged commit ab27dc9 into arviz-devs:main Mar 5, 2021
utkarsh-maheshwari pushed a commit to utkarsh-maheshwari/arviz that referenced this pull request May 27, 2021
* fix c argument

* update changelog

* 'black'

* handle c and color arguments

* fix legend and normalize cmap

* use matplotlib normalizing function

* update docstring

Co-authored-by: Oriol Abril-Pla <oriol.abril.pla@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants