Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@crazyapril
Last active October 28, 2019 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazyapril/d2cc9b5a6ce4c6c811a4f52fb8a61feb to your computer and use it in GitHub Desktop.
Save crazyapril/d2cc9b5a6ce4c6c811a4f52fb8a61feb to your computer and use it in GitHub Desktop.
cyclone symbol for matplotlib (clockwise & anticlockwise, filled & hull)
"""Cyclone symbol. Includes anticlockwise (for northern hemisphere) and
clockwise (for southern hemisphere), filled and hull variants.
The path data is derived from 'weather-icons' repository on Github. Link:
https://github.com/erikflowers/weather-icons/blob/master/svg/wi-hurricane.svg
With slight modification, the path in this file is almost identical to the
icon in the SVG file.
"""
from matplotlib.path import Path
from matplotlib.transforms import Affine2D
verts = [
(0.392, 0.003),
(0.392, 0.001),
(0.393, -0.007),
(0.392, -0.019),
(0.392, -0.036),
(0.391, -0.052),
(0.388, -0.079),
(0.382, -0.117),
(0.376, -0.155),
(0.368, -0.193),
(0.357, -0.232),
(0.329, -0.316),
(0.346, -0.271),
(0.306, -0.367),
(0.283, -0.418),
(0.256, -0.466),
(0.224, -0.511),
(0.192, -0.556),
(0.150, -0.603),
(0.098, -0.650),
(0.046, -0.697),
(-0.012, -0.739),
(-0.075, -0.774),
(-0.091, -0.783),
(-0.107, -0.785),
(-0.124, -0.780),
(-0.154, -0.765),
(-0.141, -0.775),
(-0.162, -0.749),
(-0.171, -0.733),
(-0.173, -0.717),
(-0.168, -0.699),
(-0.163, -0.682),
(-0.153, -0.668),
(-0.138, -0.660),
(-0.007, -0.588),
(0.094, -0.487),
(0.165, -0.355),
(0.111, -0.380),
(0.057, -0.393),
(0.002, -0.393),
(-0.105, -0.393),
(-0.198, -0.355),
(-0.275, -0.278),
(-0.352, -0.201),
(-0.390, -0.109),
(-0.390, -0.002),
(-0.390, 0.006),
(-0.390, 0.014),
(-0.390, 0.022),
(-0.390, 0.030),
(-0.388, 0.047),
(-0.386, 0.074),
(-0.384, 0.101),
(-0.380, 0.126),
(-0.375, 0.151),
(-0.370, 0.176),
(-0.362, 0.207),
(-0.352, 0.244),
(-0.341, 0.281),
(-0.329, 0.317),
(-0.314, 0.350),
(-0.299, 0.383),
(-0.280, 0.420),
(-0.256, 0.460),
(-0.205, 0.537),
(-0.232, 0.500),
(-0.175, 0.572),
(-0.145, 0.607),
(-0.109, 0.642),
(-0.067, 0.677),
(-0.024, 0.712),
(0.022, 0.744),
(0.072, 0.772),
(0.081, 0.778),
(0.092, 0.780),
(0.103, 0.780),
(0.129, 0.780),
(0.148, 0.768),
(0.161, 0.745),
(0.170, 0.729),
(0.172, 0.713),
(0.167, 0.696),
(0.162, 0.679),
(0.152, 0.666),
(0.136, 0.658),
(0.002, 0.583),
(-0.100, 0.480),
(-0.170, 0.350),
(-0.116, 0.376),
(-0.059, 0.388),
(0.001, 0.388),
(0.070, 0.388),
(0.135, 0.371),
(0.195, 0.336),
(0.255, 0.302),
(0.302, 0.255),
(0.338, 0.195),
(0.373, 0.137),
(0.391, 0.073),
(0.392, 0.003),
(0.392, 0.003),
]
verts_hole = [
(0.222, -0.002),
(0.222, 0.059),
(0.200, 0.111),
(0.157, 0.155),
(0.114, 0.198),
(0.062, 0.220),
(0.001, 0.220),
(-0.056, 0.220),
(-0.105, 0.201),
(-0.148, 0.163),
(-0.190, 0.125),
(-0.214, 0.078),
(-0.221, 0.022),
(-0.222, -0.001),
(-0.222, -0.003),
(-0.222, -0.005),
(-0.223, -0.006),
(-0.222, -0.066),
(-0.200, -0.117),
(-0.157, -0.158),
(-0.114, -0.200),
(-0.061, -0.220),
(-0.000, -0.220),
(0.056, -0.220),
(0.104, -0.202),
(0.146, -0.166),
(0.212, -0.084),
(0.188, -0.130),
(0.219, -0.030),
(0.222, -0.002),
]
codes = [
Path.MOVETO,
Path.LINETO,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CLOSEPOLY,
]
codes_hole = [
Path.MOVETO,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.LINETO,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CURVE4,
Path.CLOSEPOLY,
]
cyclone_path = Path(verts, codes)
clockwise_cyclone_path = cyclone_path.transformed(Affine2D().scale(-1, 1))
cyclone_path_hull = Path(verts+verts_hole, codes+codes_hole)
clockwise_cyclone_path_hull = cyclone_path_hull.transformed(
Affine2D().scale(-1, 1))
import matplotlib.pyplot as plt
from matplotlib.patches import PathPatch
from matplotlib.transforms import Affine2D
import numpy as np
from cyclone_symbol import (clockwise_cyclone_path, clockwise_cyclone_path_hull,
cyclone_path, cyclone_path_hull)
fig, ax = plt.subplots()
x = np.arange(1, 5)
y = np.ones(4)
ax.plot(x, y*1, marker=cyclone_path, markersize=15)
ax.plot(x, y*2, marker=clockwise_cyclone_path, markersize=15)
ax.plot(x, y*3, marker=cyclone_path_hull, markersize=15)
ax.plot(x, y*4, marker=clockwise_cyclone_path_hull, markersize=15)
color = '#DDDDDD'
patch1 = PathPatch(cyclone_path.transformed(Affine2D().translate(1,1)),
facecolor=color, lw=0.5)
patch2 = PathPatch(clockwise_cyclone_path.transformed(Affine2D().translate(2,2)),
facecolor=color, lw=0.5)
patch3 = PathPatch(cyclone_path_hull.transformed(Affine2D().translate(3,3)),
facecolor=color, lw=0.5)
patch4 = PathPatch(clockwise_cyclone_path_hull.transformed(Affine2D().translate(4,4)),
facecolor=color, lw=0.5)
ax.add_patch(patch1)
ax.add_patch(patch2)
ax.add_patch(patch3)
ax.add_patch(patch4)
ax.set_xlim(0, 5)
ax.set_ylim(0, 5)
ax.set_aspect('equal')
plt.savefig('cyclone_path.png')
@crazyapril
Copy link
Author

cyclone_path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment