#!/usr/bin/env python # coding: utf-8 # # Parameter `arrow` for `geom_spoke()` # # Note that the lengths of the arrow heads depend on the total lengths of the arrows. # In[1]: import numpy as np from lets_plot import * # In[2]: LetsPlot.setup_html() # In[3]: def F(xarray, yarray): return yarray, -xarray def cartesian_to_polar(xarray, yarray): rarray = np.sqrt(xarray**2 + yarray**2) return rarray / rarray.max(), np.arctan2(yarray, xarray) # In[4]: n = 11 a, b = -5, 5 space = np.linspace(a, b, n) X, Y = np.meshgrid(space, space) R, A = cartesian_to_polar(*F(X, Y)) data = dict(x=X.reshape(-1), y=Y.reshape(-1), r=R.reshape(-1), a=A.reshape(-1)) # In[5]: ggplot(data, aes('x', 'y', color='r')) + \ geom_spoke(aes(angle='a', radius='r'), \ arrow=arrow(type='closed', angle=12, length=15)) + \ scale_color_gradient(low='#3288bd', high='#d53e4f', guide='none') + \ coord_fixed(xlim=[a, b], ylim=[a, b]) + \ theme_minimal() + \ theme(axis_text=element_text(margin=10), axis_title='blank')