Opened 9 years ago
Last modified 5 years ago
#13827 new enhancement
Allow more customization in GraphPlot
Reported by: | ppurka | Owned by: | jason, ncohen, rlm |
---|---|---|---|
Priority: | major | Milestone: | sage-wishlist |
Component: | graph theory | Keywords: | |
Cc: | jmantysalo, mjo, kcrisman | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
This is my suggestion of problems and possible enhancements of graph plotting:
- For now we say either
vertex_colors='red'
orvertex_colors={'red': [1], 'blue': [2, 3]}
. But contrary to this we haveedge_color
andedge_colors
. Not good.
- Default vertex color is pink. Setting color of some vertices will change color for other vertices to light blue. Not good.
fontsize
affects to size of title font, not for vertex label or edge label font sizes.
- We have no way at all to change, say, fontsize of vertex labels or color of edge labels etc.
- And why we can have different colors in vertices, but not shapes etc?
Suggestions
Make pink true default color for vertices, so that setting color of vertex 1 will left vertex 2 to pink.(Done in #21048)
Add option(Done in #21048)vertex_color
that will be default color for vertices not colored withvertex_colors
. Deprecate use ofvertex_colors='red'
.
Allow using(Done in #21053)edge_color
andedge_colors
at same time likeedge_color='red', edge_colors={'blue': [(1, 2)]}
. (For now settingedge_colors
will change color of other edges to black, overridingedge_color
.)
- Add
title_fontsize
. Deprecatefontsize
.
- Add other options with same pattern. I.e. let we still have
vertex_shape
, but also addvertex_shapes
to be used likeG.plot(vertex_shape='s', vertex_shapes={'d': G.sources(), 'c': G.sinks()})
.
- And last, we should decide how to give options for fonts. As a triples of color, font and fontsize, or as a three argument? If as triples, do not add
title_fontsize
buttitle_font
.
First action point would be to think about my suggestion and modify it until we have common vision of what to do.
Above is a copy from dicussion, to be found easily. Here is original description:
There is no customization of text possible in plots of graphs (graphs as in graph theory). It is mentioned as a TODO in sage.graphs.graph_plot.GraphPlot.set_vertices
# TODO: allow text options for v in self._nodelist: self._plot_components['vertex_labels'].append(text(str(v), self._pos[v], rgbcolor=(0,0,0), zorder=8))
Here are some other bugs:
g = DiGraph({0:[1], 1:[0]}) g.show() # OK g.show(edge_colors={'red': [(0,1)]}) # Not OK g.show(edge_style='dotted') # OK # Docstring says edge_style "currently only works for # directed graphs" but the following works still. graphs.CompleteGraph(3).show(edge_style="dotted") # Even plain show() fails in extreme case: g1 = graphs.CompleteGraph(2) g2 = Graph({0:[1]}) print(g1==g2) # True g1.show() # Not shown g2.show() # Shown
"For all the constructors in this database (except the octahedral, dodecahedral, random and empty graphs), the position dictionary is filled in" -- it is filled in octahedral and dodecahedral graph.
Change History (20)
comment:1 Changed 8 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:2 Changed 8 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:3 Changed 7 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:4 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:5 Changed 6 years ago by
- Cc jmantysalo added
- Summary changed from Allow customization of text in GraphPlot to Allow more customization in GraphPlot
comment:6 Changed 6 years ago by
- Cc mjo added
comment:7 Changed 6 years ago by
Just pinging... Any comments on my suggestions?
comment:8 follow-up: ↓ 9 Changed 6 years ago by
- Cc kcrisman added
Make pink true default color for vertices, so that setting color of vertex 1 will left vertex 2 to pink.
Maybe it should be blue/sage color, so as to be default with the sage plots.
Instead of adding many keyword arguments for the overall plot command, it might be better to let the methods take care of the setting.
set_vertices
could be used to set only vertex properties.set_edges
for setting only edge property.- Maybe introduce a different
set_plot_font
because it seems customizing all the different font properties is going to be a complicated method in itself. - Introduce the
vertex_shapes
and such other vertex related properties not inplot
but in theset_vertex
method.
Adding kcrisman for his expert comments :-)
comment:9 in reply to: ↑ 8 Changed 6 years ago by
Replying to ppurka:
Make pink true default color for vertices, so that setting color of vertex 1 will left vertex 2 to pink.
Maybe it should be blue/sage color, so as to be default with the sage plots.
Whatever. But I suppose that we agree that setting color of vertex 1 should not change color of vertex 2.
Instead of adding many keyword arguments for the overall plot command, it might be better to let the methods take care of the setting. - -
- Introduce the
vertex_shapes
and such other vertex related properties not inplot
but in theset_vertex
method.
so we would have something like
p = G.plot() p.set_vertex(('shapes', {'d': G.sources()}), ('colors', ...)) p.show()
? Sounds complicated.
comment:10 follow-up: ↓ 11 Changed 6 years ago by
I was thinking it would more like
p.set_vertex(shapes=..., colors=...) p.set_edges(colors=...) p.set_plot(fontsize=..., font=...) # or set_plot_font, if the only extra thing left to customize is fonts
comment:11 in reply to: ↑ 10 Changed 6 years ago by
Replying to ppurka:
I was thinking it would more like
p.set_vertex(shapes=..., colors=...)
But isn't it still much more complicated than just giving options in plot
?
comment:12 follow-up: ↓ 13 Changed 6 years ago by
In my opinion, it will get unwieldy if all the options are put into plot. Making a plot will involve a massive single line of p.plot(shapes=, colors=, fonts=,....)
. Breaking it up into multiple methods should make it clearer which methods control which aspects of the graph.
From the programming point of view, it should also make the functions more manageable. Otherwise, all of that code will end up in a single huge function plot
.
comment:13 in reply to: ↑ 12 Changed 6 years ago by
Replying to ppurka:
In my opinion, it will get unwieldy if all the options are put into plot. Making a plot will involve a massive single line of
p.plot(shapes=, colors=, fonts=,....)
. Breaking it up into multiple methods should make it clearer which methods control which aspects of the graph.
It depends. User may not use all possible options. And if he/she uses, then it won't be that much easier with several lines of settings. And one can say
edge_colors = ... # something complicated ... vertex_shapes = ... # something complicated ...plot(edge_colors=edge_colors, ...)
From the programming point of view, it should also make the functions more manageable. Otherwise, all of that code will end up in a single huge function
plot
.
I guess that backend should have set_edges
and so on. But plot
can call them.
I believe that there is not very good solution. There are just too many options that could be useful to someone. OTOH reducing possible options sounds odd. So we can only make sure that the design is as orthogonal as it can.
comment:14 Changed 6 years ago by
- Description modified (diff)
- Milestone changed from sage-6.4 to sage-wishlist
comment:15 Changed 6 years ago by
Still about the desing... I the user is plotting just one graph, it is easier to have single plot()
with massive list of options.
If the user wants to plot same graph somehow modified, then it will be easier to do something like
G.set_vertex_shape('a', 'rectangle') G.set_vertex_shape('b', 'circle') G.show() G.do_something_inplace('a', 'x') G.show()
From these choised I would choose first one. I would make a plot()
with huge list of options, and internally set_vertices()
and set_edges()
with a manageable number of options.
comment:16 follow-up: ↓ 17 Changed 6 years ago by
We can have both, can't we?
Make plot()
be able to take multiple arguments and set them using the other custom functions. This will take care of my concerns in comment:13
comment:17 in reply to: ↑ 16 Changed 6 years ago by
Replying to ppurka:
We can have both, can't we?
Make
plot()
be able to take multiple arguments and set them using the other custom functions. This will take care of my concerns in comment:13
Yes, that can be done.
comment:18 Changed 5 years ago by
First part is at #21048.
comment:19 Changed 5 years ago by
- Description modified (diff)
comment:20 Changed 5 years ago by
- Description modified (diff)
vertex_colors='red'
orvertex_colors={'red': [1], 'blue': [2, 3]}
. But contrary to this we haveedge_color
andedge_colors
. Not good.fontsize
affects to size of title font, not for vertex label or edge label font sizes.Suggestions
vertex_color
that will be default color for vertices not colored withvertex_colors
. Deprecate use ofvertex_colors='red'
.edge_color
andedge_colors
at same time likeedge_color='red', edge_colors={'blue': [(1, 2)]}
. (For now settingedge_colors
will change color of other edges to black, overridingedge_color
.)title_fontsize
. Deprecatefontsize
.vertex_shape
, but also addvertex_shapes
to be used likeG.plot(vertex_shape='s', vertex_shapes={'d': G.sources(), 'c': G.sinks()})
.title_fontsize
buttitle_font
.First action point would be to think about my suggestion and modify it until we have common vision of what to do.