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

Different color maps between :gradient and other settings #10

Open
davide-f opened this issue Apr 19, 2021 · 4 comments
Open

Different color maps between :gradient and other settings #10

davide-f opened this issue Apr 19, 2021 · 4 comments

Comments

@davide-f
Copy link
Collaborator

davide-f commented Apr 19, 2021

Dear developer,

While using the code, I experienced problems with the :gradient settings.
In particular, the node colors changed when using the option :gradient, with respect to the others.
With the :gradient, the outcome is the following:
image
With no :gradient setting (thus the standard setting), the output is the following:
image

For reproducibility, this is the source with the :gradient [to run this code, you need the change in the pull request]

data = [1.0  12.0  0.970741
  2.0  11.0  0.099867
  2.0  10.0  0.0874267
 10.0  12.0  0.0233846
  2.0  12.0  0.542539
  1.0  13.0  0.388331
  3.0  11.0  0.0804934
  3.0  10.0  0.110872
 10.0  13.0  0.00206157
  3.0  13.0  0.221796
  1.0  14.0  0.468872
  4.0  11.0  0.185785
  4.0  10.0  0.278111
 10.0  14.0  0.00151853
  4.0  14.0  0.763057
  1.0  15.0  0.353096
  5.0  11.0  0.000423724
  5.0  10.0  0.000141012
 10.0  15.0  0.242061
  5.0  15.0  0.208177
  1.0  16.0  0.970009
  6.0  11.0  0.0001099
  6.0  10.0  3.7705e-5
 10.0  16.0  0.222575
  6.0  16.0  0.208594
  1.0  17.0  0.584011
  7.0  11.0  0.139244
  7.0  10.0  0.189689
 10.0  17.0  0.000833531
  7.0  17.0  0.286463
  1.0  18.0  0.601005
 10.0  18.0  0.278003
  1.0  19.0  0.311745
  8.0  11.0  0.146233
  8.0  10.0  0.252754
 10.0  19.0  0.000103437
  8.0  19.0  0.553732
  1.0  20.0  0.44891
  9.0  11.0  0.127771
  9.0  10.0  0.182001
 10.0  20.0  0.00132186
  9.0  20.0  0.498821
  1.0  21.0  0.519072
 10.0  21.0  0.32917]

tot_colors = vcat(palette(:rainbow)[2],
   palette(:default)[1:length(user_set)],
   palette(:rainbow)[5],
   palette(:rainbow)[2],
   palette(:default)[1:length(user_set)])

sankey(convert(Vector{Int}, data[:, 1]), convert(Vector{Int}, data[:, 2]), data[:, 3];
        edge_color=:gradient,
        node_colors=tot_colors,
        compact=true)

The code used without the :gradient is the following.

sankey(convert(Vector{Int}, data[:, 1]), convert(Vector{Int}, data[:, 2]), data[:, 3];
        node_colors=tot_colors,
        compact=true)

Options :src and :dst work as expected, instead. I am also investigating the issue, but the bug is very challenging to find, my guess is that the bug may be in the calculations of the "rectangles" used to draw the gradient, in the Recipe, or in some default Plot settings (unlikely maybe). However, for the first case, it is difficult for me to read the source unfortunately.

@davide-f
Copy link
Collaborator Author

Any hint would be much apprecciated

@davide-f
Copy link
Collaborator Author

davide-f commented Apr 20, 2021

I updated the figures so to clarify the impact of the issue: nodes 3,7,8,9,15,17,19 and 20 completely changed their colors; moreover, the weird shaping occurs.

@davide-f
Copy link
Collaborator Author

The smallest example reproducing the error is shown below: notice the change in the color of "Node 12".

using Plots, SankeyPlots
data = [
  10.0  12.0  0.2233846
   1.0  13.0  0.388331
   1.0  14.0  0.468872
   3.0  11.0  0.0804934
   3.0  10.0  0.110872
  10.0  13.0  0.00206157
   3.0  13.0  0.221796
   4.0  11.0  0.185785
   4.0  10.0  0.278111
  10.0  14.0  0.00151853
   4.0  14.0  0.763057
   1.0  15.0  0.353096
  ]

tot_colors = vcat(palette(:rainbow)[2],
   palette(:default)[1:10],
   palette(:rainbow)[5],
   palette(:rainbow)[2],
   palette(:default)[1:10])

a = sankey(convert(Vector{Int}, data[:, 1]), convert(Vector{Int}, data[:, 2]), data[:, 3];
        node_colors=tot_colors,
        edge_color=:gradient,
        compact=true)
display(a)


b = sankey(convert(Vector{Int}, data[:, 1]), convert(Vector{Int}, data[:, 2]), data[:, 3];
        node_colors=tot_colors,
        compact=true)
display(b)

I tried to debug it at RecibeBase; in particular, I showed the variable "series_list" at line 286 of ReceipeBase, to highlight whether the block Node12 were plotted with the right color in a and b. In the word files, I show the two plots and the differences highlighted. The output of ReceipeBase seems to be consistent; I add an issue also on Plots.
a.docx
a versus b.docx
b.docx

@davide-f
Copy link
Collaborator Author

I tested plotly and pyplot backends and the error does not occur, thus it is likely a Plots.jl problem; I added the issue in Plots accordingly: JuliaPlots/Plots.jl#3446

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

No branches or pull requests

1 participant