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

plot_trace with combined=True to have alternating colors and labels #837

Closed
julian-pani opened this issue Sep 30, 2019 · 3 comments · Fixed by #1070
Closed

plot_trace with combined=True to have alternating colors and labels #837

julian-pani opened this issue Sep 30, 2019 · 3 comments · Fixed by #1070
Labels
Enhancement Improvements to ArviZ Usability

Comments

@julian-pani
Copy link

Tell us about it

I'm very new at this, so not sure how much this problem is relevant for other users.
When using plot_trace with combined=True:

import matplotlib as plt
import arviz as az
data = az.load_arviz_data('non_centered_eight')
ax = az.plot_trace(data, var_names=('theta_t', 'theta'), combined=True, compact=True, figsize = (20, 8))

the lines come up in the same color and without labels, so it's hard to differenciate between them
Screenshot from 2019-09-30 17-06-18

It would be great to have colors by default in the lines. And maybe an option to show labels
Something like:
Screenshot from 2019-09-30 17-05-55

Thoughts on implementation

Alternating colors - I don't see any reason not to have them.
For the labels - I understand that there could be thousands of lines, so maybe have a limit, to show something like the first 5 labels, or maybe add an argument to the method with num_labels (and then show "..." to indicate there are more not being shown)

I've been looking at https://arviz-devs.github.io/arviz/_modules/arviz/plots/traceplot.html for a while but it's way above my league. I just don't understand what's going on.

Thanks for reading!

@canyon289
Copy link
Member

@julian-pani Apologies on missing this issue for the last couple months.

The traceplot lines should show up in different colors now. I checked the latest example to verify. Are you still having this issue?

https://arviz-devs.github.io/arviz/examples/matplotlib/mpl_plot_trace.html

@OriolAbril
Copy link
Member

I think it is still an issue, because plot_trace accepts both combined and compact argument. Thus, there are 4 cases to take into account:

  1. combined = compact = False (default case). Multidimensional variables are plotted on different subplots, and chains are not combined, thus, each kde subplot has nchains lines. This is the case of the example, where each line has a different color. Moreover, using legend=True will automatically generate a legend with the chain color code.
  2. combined = True; compact = False. Multidimensional variables are plotted on different subplots, and chains are combined. Thus, each kde subplot has 1 line. I don't think legend would currently work in this case, but the title already gives all the information, it is not a priority to get a legend working here.
  3. combined=True; compact=True. Multidimensional variables have all components plotted in the same subplot (this is @julian-pani's case). Thus, each subplot has as many lines as the dimension of the variable. Legend and coloring do not work because they currently only code chain information.
  4. combined=False; compact=True. Multidimensional variables have all componensts plotted in the same subplot, and chains are not combined. Each subplot has nchains*shape lines. The color and legend should correctly represent the chain information, but all the information on the variable coordinate is lost (much like in the previous case).

The solution would be to have:

  1. Coloring and legend based only on chain. Already implemented.
  2. Nothing to implement I think.
  3. Coloring and legend based only on variable coordinate. TODO
  4. Coloring based on chain and linestyle? based on coordinate (or viceversa, depending on new arg/rcparam/which is larger). I think the ideal case would be having 2 legends, one with the chain info and the other with the coordinate info. TODO

@OriolAbril OriolAbril added Enhancement Improvements to ArviZ Usability labels Jan 5, 2020
@OriolAbril OriolAbril mentioned this issue Feb 16, 2020
5 tasks
@AbhishekKumarSingh
Copy link

AbhishekKumarSingh commented Sep 9, 2021

use compact=False and it should work. By default compact=True in newer version.

ax = az.plot_trace(data, var_names=('theta_t', 'theta'), compact=False, figsize = (20, 8))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improvements to ArviZ Usability
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants