Consistent colour scale and legend
Hi, I'm trying to use graph-tool to track concentrations on a network and was wondering what the best way would be to obtain consistent colour scales for a vertex property? I track the concentration of a substance as a vertex property and then use that as the vertex_fill_color in graph_draw because I would like to visualise the change in concentration over the network over time. This works great, but it appears that every time I plot the graph the colormap is rescaled to the minimum and maximum values in the vertex property. So if my values range from 0.0 to 0.4 and I use the Blues colormap 0.0 is white and 0.4 is dark blue. If in the next time step my values range from 0.0 to 0.6 then 0.6 is dark blue and 0.4 is now a different shade of blue. Instead, if I know 0.0 would be the minimum value and 1.0 would be the maximum I would like to consistently plot my graphs using that scaling, so that 0.4 always has the same shade of blue. I hope this all made sense. Thanks! Alexandra
You can use matplotlib and a colormap for this. I think you need to create a vp that's only for the colors, the documentation says which types are accepted for colors. You can get a color with a cmap by pasing a value from 0 - 1. See this example for using a cmap: import matplotlib.pyplot as plt cmap = plt.get_cmap('cool') cmap(0.4) (0.40000000000000002, 0.59999999999999998, 1.0, 1.0) On Fri, Feb 26, 2016 at 12:35 PM, Alexandra Diem <alexandra.diem@gmail.com> wrote:
Hi, I'm trying to use graph-tool to track concentrations on a network and was wondering what the best way would be to obtain consistent colour scales for a vertex property? I track the concentration of a substance as a vertex property and then use that as the vertex_fill_color in graph_draw because I would like to visualise the change in concentration over the network over time. This works great, but it appears that every time I plot the graph the colormap is rescaled to the minimum and maximum values in the vertex property. So if my values range from 0.0 to 0.4 and I use the Blues colormap 0.0 is white and 0.4 is dark blue. If in the next time step my values range from 0.0 to 0.6 then 0.6 is dark blue and 0.4 is now a different shade of blue. Instead, if I know 0.0 would be the minimum value and 1.0 would be the maximum I would like to consistently plot my graphs using that scaling, so that 0.4 always has the same shade of blue. I hope this all made sense. Thanks! Alexandra
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
Cheers, I managed to get the colours consistent with your suggestion. One more thing I forgot to ask in my original post, is there a way to display a colour legend with the graph plot? On Fri, 26 Feb 2016 at 11:54 Joel Moberg <joel.moberg@gmail.com> wrote:
You can use matplotlib and a colormap for this. I think you need to create a vp that's only for the colors, the documentation says which types are accepted for colors. You can get a color with a cmap by pasing a value from 0 - 1.
See this example for using a cmap:
import matplotlib.pyplot as plt cmap = plt.get_cmap('cool') cmap(0.4) (0.40000000000000002, 0.59999999999999998, 1.0, 1.0)
On Fri, Feb 26, 2016 at 12:35 PM, Alexandra Diem <alexandra.diem@gmail.com
wrote:
Hi, I'm trying to use graph-tool to track concentrations on a network and was wondering what the best way would be to obtain consistent colour scales for a vertex property? I track the concentration of a substance as a vertex property and then use that as the vertex_fill_color in graph_draw because I would like to visualise the change in concentration over the network over time. This works great, but it appears that every time I plot the graph the colormap is rescaled to the minimum and maximum values in the vertex property. So if my values range from 0.0 to 0.4 and I use the Blues colormap 0.0 is white and 0.4 is dark blue. If in the next time step my values range from 0.0 to 0.6 then 0.6 is dark blue and 0.4 is now a different shade of blue. Instead, if I know 0.0 would be the minimum value and 1.0 would be the maximum I would like to consistently plot my graphs using that scaling, so that 0.4 always has the same shade of blue. I hope this all made sense. Thanks! Alexandra
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
On 29.02.2016 12:11, Alexandra Diem wrote:
Cheers, I managed to get the colours consistent with your suggestion. One more thing I forgot to ask in my original post, is there a way to display a colour legend with the graph plot?
The only way to do that is to embed the drawing into a matplotlib figure (via the mplfig parameter of graph_draw()), and then insert a legend from there. Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
Thanks for you reply! I'm not sure I really understand how this works properly, the only example I could find is here: http://stackoverflow.com/questions/34425955/make-coordinate-systems-agree-be... so I tried something similar for my plot: ax = plt.gca() gt.graph_draw(g, pos=pos, vertex_fill_color=concentration, output=fname, vcmap=cmap, vertex_shape=groups, vertex_size=7, mplfig=ax) #plt.colorbar() This results in all my nodes just being black instead of shades of blue as they are if I don't use mplfig. Additionally, I would like colorbar() to use the vertex property concentration, but I can't find any information on how I might be able to do this. Your help is greatly appreciated! Regards Alexandra On Tue, 1 Mar 2016 at 10:14 Tiago de Paula Peixoto <tiago@skewed.de> wrote:
On 29.02.2016 12:11, Alexandra Diem wrote:
Cheers, I managed to get the colours consistent with your suggestion. One more thing I forgot to ask in my original post, is there a way to display a colour legend with the graph plot?
The only way to do that is to embed the drawing into a matplotlib figure (via the mplfig parameter of graph_draw()), and then insert a legend from there.
Best, Tiago
-- Tiago de Paula Peixoto <tiago@skewed.de>
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
In case that you managed to add a colorbar, would you please post the solution. -- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
participants (4)
-
Alexandra Diem -
Joel Moberg -
Kimon -
Tiago de Paula Peixoto