In [1]:
require 'matplotlib/iruby'
Matplotlib::IRuby.activate
plt = Matplotlib::Pyplot

require 'pycall/import'
include PyCall::Import
pyimport :numpy, as: :np


Out[1]:
:np

In [2]:
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
nil

In [3]:
ax = plt.subplot(111, projection: 'polar')
ax.plot(theta, r)
ax.set_rmax(2)
ax.set_rticks([0.5, 1, 1.5, 2])   # less radial ticks
ax.set_rlabel_position(-22.5)  # get radial labels away from plotted line
ax.grid(true)

ax.set_title("A line plot on a polar axis", va: 'bottom')
nil


Out[3]:

In [4]:
n = 150
r = 2 * np.random.rand(n)
theta = 2 * np.pi * np.random.rand(n)
area = 200 * r**2
colors = theta
nil

In [5]:
ax = plt.subplot(111, projection: 'polar')
c = ax.scatter(theta, r, c: colors, s: area, cmap: 'hsv', alpha: 0.75)


Out[5]:
Out[5]:
#<Object:0x007f94079472d8 @__pyptr__=#<PyCall::PyPtr:0x007f94079472b0 type=PathCollection addr=0x000001098a54a8>>

In [6]:
n = 20
theta = np.linspace(0.0, 2 * np.pi, n, endpoint: false)
radii = 10 * np.random.rand(n)
width = np.pi / 4 * np.random.rand(n)
nil

In [7]:
ax = plt.subplot(111, projection: 'polar')
bars = ax.bar(theta, radii, width: width, bottom: 0.0)

# TODO: I want to the following line in `PyCall.zip(radii, bars).each do |r, bar|`
radii.tolist.zip(PyCall::List.new(bars)) do |r, bar|
  # r = radii[i]
  bar.set_facecolor(plt.cm.viridis(r / 10.0))
  bar.set_alpha(0.5)
end

nil


Out[7]:

In [ ]: