holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.03k stars 99 forks source link

Attribute 'connectionstyle' ignored, impossible to curve the graph edges. #683

Open agicquel opened 2 years ago

agicquel commented 2 years ago

ALL software version info

python 3.10 bokeh 2.4.2 networkx 2.6.2

Description of expected behavior and the observed behavior

I tried to draw directed graph along with the multipartite layout from networkx. The graph is rendered however all the edges overlap between each other. To correct this behavior, I added the 'connectionstyle' attribute in order to curve the edges in function draw_networkx_edges but the edges are still straight.

Complete, minimal, self-contained example code that reproduces the issue

defaults = dict(width=1600, height=1000)
hv.opts.defaults(opts.EdgePaths(**defaults), opts.Graph(**defaults), opts.Nodes(**defaults))pos = nx.layout.multipartite_layout(self.nx_cfg, subset_key="address", align="horizontal", scale=4)

nodes = hvnx.draw_networkx_nodes(self.nx_cfg, pos, node_size=30, node_color='blue')
edges = hvnx.draw_networkx_edges(self.nx_cfg, pos, node_size=30, arrows=True, arrowstyle=']->',
                                         arrowsize=10, edge_color="green", connectionstyle="arc3",
                                         edge_cmap='Blues', edge_width=2, colorbar=True)

show(hv.render(nodes * edges))
maximlt commented 2 years ago

Hi @agicquel, I believe the parameter connectionstyle is neither supported by hvplot nor by 'holoviews'.

This parameter is available in the function draw_networkx_edges provided by networkx (returning a Matplotlib object), but not by its equivalent function provided by hvplot. I don't think, but I'm not 100% sure, that this sort of styling is available in Bokeh.

Soon hvplot users will have the availability to use the Matplotlib backend instead of just Bokeh. I'm thus marking this issue as a feature request.

agicquel commented 2 years ago

Hi @maximlt and thanks for you reply. You're right, this option is only provided by networkx and Bokeh don't provide any option of this kind.

From my understanding, an edge is drawn using a path, i.e. a list of points in the graph. So, is it possible to provide a user function in the graph constructor to compute the desired path for each pair of nodes with an edge ?

maximlt commented 2 years ago

It looks like you can do that with holoviews by explicitly passing coordinates of each edge. I don't expect that to be trivial however, but I'd be happy if you can prove me wrong!

agicquel commented 2 years ago

Okay thank you. I'll let you know if I code something to make this easier!