mpl_chord_diagram icon indicating copy to clipboard operation
mpl_chord_diagram copied to clipboard

Unique arc colors

Open folkien opened this issue 1 year ago • 4 comments

Added possibility to give longer chord_colors list to define each separated arc color.

Now each arc calculates individual color from chord_colors list. If list is shorter then color is selected modulo list length.

ps. Examples also updated with 5-th example with different arc colors test.

folkien avatar Dec 16 '23 17:12 folkien

Hi @folkien thanks for the PR! Being able to set specific colors for chords is definitely a useful addition.

However, I wonder whether this is the best way to add it, as it feels unlikely that people would set all individual chords' colors, and a flat list is not the most convenient way to specify which chords should be colored as we start from a matrix.

I would propose to request a defaultdict accepting (i, j) and (rowname, colname) as keys (so the default color can be chosen by the user).

In case you haven't used defaultdict before, it would go like:

from collections import defaultdict

ccolors = defaultdict(lambda: "grey", {(0, 1): "blue", (1, 2): "red"})  # default color is grey

print(ccolors[(0, 0)])  # grey
print(ccolors[(0, 1)])  # blue

To be honest, for me using this dict it's overengineering this feature. Default mechanism of cmap and chord_colors are very good in many situations. But for me, i would like to specify arc colors beause i'm using this chart for traffic intersection diagram where every traffic relation has own individual color. So i have to specify every arc color anyway.

Example QuantityRelationsCartogram

folkien avatar Dec 18 '23 09:12 folkien

To be honest, for me using this dict it's overengineering this feature. Default mechanism of cmap and chord_colors are very good in many situations. But for me, i would like to specify arc colors beause i'm using this chart for traffic intersection diagram where every traffic relation has own individual color. So i have to specify every arc color anyway.

I understand that you have a specific use case, however, I'm not comfortable with the way the feature is implemented at the moment as it's not generic enough to accommodate other use cases that I feel should be supported if we include a "color specific chords" feature.

Would it really be that cumbersome for you to switch to a dict format? (if all entries are provided, it does not need to be a defaultdict)

Pinging @gph82 to hear his opinion on the PR.

tfardet avatar Dec 18 '23 09:12 tfardet

Changes added today.

  • ideogram_colors argument added
  • chord_colors can be specified per node or per arc or per everything,

folkien avatar Dec 21 '23 10:12 folkien

@folkien sorry, it seems Guillermo is not available at the moment I have a deadline on February 9 so I'll look at this afterwards. Just to clarify one thing: if I were to adapt the PR to use a dictionary myself, would it be OK for you or do you have a strong preference for a list?

tfardet avatar Jan 24 '24 08:01 tfardet