-
Notifications
You must be signed in to change notification settings - Fork 141
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
Add optional keywords to GraphOptimizationApplication.draw
#52
Comments
Currently, matplotlib is used with networkx to draw a graph. However, we might change the library for visualization. @mtreinish is working on, so please leave this issue for now. |
Right, I'm hoping to migrate qiskit-optimization to use retworkx internally instead of networkx for performance. Right now retworkx only supports generating a import retworkx
import pydot
graph = retworkx.undirected_gnm_random_graph(7, 10, seed=123)
graph.update_edge(2, 4, 'red')
graph.update_edge(1, 3, 'red')
graph.update_edge(1, 5, 'red')
def node_attrs(node):
out_dict = {'style': 'filled'}
if node % 2 == 0:
out_dict['fillcolor'] = 'red'
else:
out_dict['fillcolor'] = 'grey'
return out_dict
def edge_attrs(edge):
out_dict = {}
if edge:
out_dict['color'] = edge
out_dict['penwidth'] = '4.0'
return out_dict
dot_str = graph.to_dot(node_attrs, edge_attrs)
dot = pydot.graph_from_dot_data(dot_str)[0]
dot.write_png('graph.png') generates a graph image like: That being said for the next retworkx release I'm working on adding a matplotlib visualization function: Qiskit/rustworkx#304 (it's still pretty rough, but hopefully I'll be able to clean it up before too long) so we might not need to adapt things here if/when we switch to retworkx since if we wait for retworkx 0.9 we hopefully should have a matplotlib drawer available. As an aside as we're preparing the networkx release please file issues at https://github.com/Qiskit/retworkx/issues for any gaps in retworkx for things that qiskit-optimization needs so we can make sure retworkx has all the functionality needed for qiskit-optimization. |
What is the expected enhancement?
If we add optional keywords (i.e., kwargs) to
GraphOptimizationApplication.draw
, users can control all options of networkx.draw.https://networkx.org/documentation/stable/reference/generated/networkx.drawing.nx_pylab.draw.html#networkx.drawing.nx_pylab.draw
The text was updated successfully, but these errors were encountered: