Skip to content
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

[draft] Passing ax to some plot functions #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions cotengra/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ def plot_contractions(
color_size=(0.6, 0.4, 0.7),
color_cost=(0.3, 0.7, 0.5),
figsize=(8, 3),
ax=None,
):
import matplotlib.pyplot as plt

Expand All @@ -1160,12 +1161,15 @@ def plot_contractions(
sz -= tree.get_size(l)
sz -= tree.get_size(r)
sizes.append(math.log2(tree.get_size(p)))

costs.append(math.log10(tree.get_flops(p)))

cons = list(range(len(peaks)))

fig, ax = plt.subplots(figsize=figsize)

if ax is None:
fig, ax = plt.subplots(figsize=figsize)
else:
fig = None
ax.set_xlabel("contraction")

ax.plot(
Expand Down Expand Up @@ -1552,8 +1556,6 @@ def plot_tree_rubberband(
tree,
order=None,
colormap="Spectral",
with_edge_labels=None,
with_node_labels=None,
highlight=(),
centrality=False,
layout="auto",
Expand Down Expand Up @@ -1598,6 +1600,7 @@ def plot_tree_rubberband(
figsize=figsize,
info=info,
show_and_close=False,
ax=ax,
)
pos = info["pos"]
r0 = info["node_size"]
Expand Down Expand Up @@ -1647,6 +1650,7 @@ def plot_tree_flat(
node_labels_font_family="monospace",
show_sliced=True,
figsize=None,
ax=None,
):
"""Plot a ``ContractionTree`` as a flat, 2D diagram, including all indices
at every intermediate contraction. This can be useful for small
Expand Down Expand Up @@ -1720,7 +1724,7 @@ def plot_tree_flat(
family=node_labels_font_family,
)

d = Drawing(figsize=figsize)
d = Drawing(ax=ax, figsize=figsize)

# order the leaves are contracted in
leaf_order = {leaf: i for i, leaf in enumerate(tree.get_leaves_ordered())}
Expand Down Expand Up @@ -1877,6 +1881,7 @@ def plot_tree_circuit(
node_colormap="YlOrRd",
node_max_size=None,
figsize=None,
ax=None,
):
import matplotlib as mpl

Expand All @@ -1885,7 +1890,7 @@ def plot_tree_circuit(
if figsize is None:
figsize = (tree.N**0.75, tree.N**0.75)

d = Drawing(figsize=figsize)
d = Drawing(ax=ax, figsize=figsize)

# edge coloring -> node size
if edge_max_width is None:
Expand Down