Skip to content

Instantly share code, notes, and snippets.

@goretkin
Created May 13, 2021 01:45
Show Gist options
  • Save goretkin/a69f81ff9d9b4d6a891ccd9eb8cf8799 to your computer and use it in GitHub Desktop.
Save goretkin/a69f81ff9d9b4d6a891ccd9eb8cf8799 to your computer and use it in GitHub Desktop.
matplotlib polycollection svg
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
using PyPlot
PolyCollection = PyPlot.matplotlib.collections.PolyCollection
polygon = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]]
# force new axes
ax = PyPlot.axes(label=string(Base.UUID(rand(UInt128))))
ax.set_aspect(1.0)
n = 2000
hb = ax.hexbin(randn(n), 6 * rand(n); gridsize=20)
#=
offsets = 100 .* rand(n, 2)
# https://github.com/matplotlib/matplotlib/blob/40862a32e86ed3a9a67790dc249da13971f1a37d/lib/matplotlib/axes/_axes.py#L4886-L4892
poly_collection = PolyCollection(
[polygon],
offsets = offsets,
edgecolors = "face",
facecolors = rand(n, 4),
transOffset = matplotlib.transforms.AffineDeltaTransform(ax.transData),
)
(xmin, xmax) = extrema(offsets[1, :])
(ymin, ymax) = extrema(offsets[2, :])
corners = ((xmin, ymin), (xmax, ymax))
ax.update_datalim(corners)
ax._request_autoscale_view(tight=true)
ax.add_collection(poly_collection, autolim=false)
=#
display(ax.figure)
ax.figure.savefig("hex.svg")
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment