-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
[ENH]: Band and Sankey Diagramm #28227
Comments
sankey: https://matplotlib.org/stable/gallery/specialty_plots/sankey_basics.html To build exact replicas of these I think you need gradients: https://matplotlib.org/stable/gallery/lines_bars_and_markers/gradient_bar.html Something we don't have (that I know of) is code like from matplotlib.path import Path
def make_connector_path(x1, y1, y2, w, h, *, scale=0.2):
h1 = h2 = h
y3 = y2 + h2
y4 = y1 + h1
x2 = x1 + w
mid1 = x1 * scale + x2 * (1 - scale)
mid2 = x2 * scale + x1 * (1 - scale)
pt1 = (x1, y1)
ctla_1 = (mid1, y1)
ctla_2 = (mid2, y2)
pt2 = (x2, y2)
pt3 = (x2, y3)
ctlb_1 = (mid2, y3)
ctlb_2 = (mid1, y4)
pt4 = (x1, y4)
pathdata = [
(Path.MOVETO, pt1),
(Path.CURVE4, ctla_1),
(Path.CURVE4, ctla_2),
(Path.CURVE4, pt2),
(Path.LINETO, pt3),
(Path.CURVE4, ctlb_1),
(Path.CURVE4, ctlb_2),
(Path.CURVE4, pt4),
(Path.CLOSEPOLY, pt1),
]
codes, verts = zip(*pathdata)
path = Path(verts, codes)
return path that is parameterized to make generating those connector patches a bit nicer (and you can use that path to clip a gradient). If you assume both ends of the connector are the same height and the curve and the connector is symmetric, you only actually have 5 (position) + 1 (shape) degrees of freedom but need 18 values so there are a lot of ways to parameterize this function. This is what felt right to me sketching it out, but no idea if it is the "right" parameterization. import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backend_bases import MouseButton
from matplotlib.patches import PathPatch
fig, (ax, ax2) = plt.subplots(1, 2, sharex=True, sharey=True)
x1 = -1
w = 3
x2 = x1 + w
y1 = -1
y2 = 0
h = 2
y3 = y2 + h
path = make_connector_path(x1=x1, y1=y1, y2=y2, w=w, h=h)
patch = PathPatch(path, facecolor="green", edgecolor="yellow", alpha=0.5)
ax.add_patch(patch)
(ln,) = ax.plot(*zip(*path.vertices), marker="o", markerfacecolor="r")
im = ax2.imshow(np.tile(range(128), (128, 1)), extent=(x1, x2, y1, y3), aspect='auto')
im.set_clip_path(path, transform=ax2.transData)
ax.set_xlim(-3, 4)
ax.set_ylim(-3, 4)
plt.show() These plots are very specialized and I expect that there is a variety of reasonable ways structure the input data. I suspect a complete In terms of both effort I think the path here is:
|
https://matplotlib.org/stable/api/sankey_api.html Have you looked at this for making sankey diagrams in matplotlib? Is it missing a feature you want? |
Problem
Sanky Diagram ↓
Band Diagram ↓
Proposed solution
No response
The text was updated successfully, but these errors were encountered: