Skip to content

Commit 3610c33

Browse files
author
Corey Ostrove
committed
Move matplotlib import
Move a matplotlib import into _draw_graph to avoid one-off dependency issue.
1 parent 6fc2e80 commit 3610c33

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pygsti/layouts/prefixtable.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import collections as _collections
1414
import networkx as _nx
15-
import matplotlib.pyplot as plt
1615
from math import ceil
1716
from pygsti.baseobjs import Label as _Label
1817
from pygsti.circuits.circuit import SeparatePOVMCircuit as _SeparatePOVMCircuit
@@ -1208,6 +1207,14 @@ def _draw_graph(G, node_label_key='label', edge_label_key='promotion_cost', figu
12081207
An optional size specifier passed into the matplotlib figure
12091208
constructor to set the plot size.
12101209
"""
1210+
try:
1211+
import matplotlib.pyplot as plt
1212+
except ImportError as e:
1213+
msg = 'The function `_draw_graph` requires the installation of matplotlib.'\
1214+
+'Please ensure this is properly installed and try again.'
1215+
print(msg)
1216+
raise e
1217+
12111218
plt.figure(figsize=figure_size)
12121219
pos = _nx.nx_agraph.graphviz_layout(G, prog="dot", args="-Granksep=5 -Gnodesep=10")
12131220
labels = _nx.get_node_attributes(G, node_label_key)

0 commit comments

Comments
 (0)