Skip to content

Commit a99f7a7

Browse files
committed
Add Pyplot.xkcd wrapper
1 parent 7399671 commit a99f7a7

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/matplotlib/pyplot.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def __pyobj__
1818
@pyplot
1919
end
2020

21+
def xkcd(scale: 1, length: 100, randomness: 2, &block)
22+
PyCall.with(super.(scale: scale, length: length, randomness: randomness), &block)
23+
end
24+
2125
def method_missing(name, *args, **kwargs)
2226
return super unless PyCall.hasattr?(@pyplot, name)
2327
PyCall.getattr(@pyplot, name)

spec/matplotlib/pyplot_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'spec_helper'
2+
require 'matplotlib/pyplot'
3+
4+
module Matplotlib
5+
::RSpec.describe Pyplot do
6+
describe '.xkcd' do
7+
specify do
8+
expect { |b| Pyplot.xkcd(&b) }.to yield_control
9+
end
10+
11+
specify do
12+
saved_font_family = Matplotlib.rcParams['font.family']
13+
saved_path_sketch = Matplotlib.rcParams['path.sketch']
14+
Pyplot.xkcd(scale: 42, length: 43, randomness: 44) do
15+
expect(Matplotlib.rcParams['font.family']).to include('xkcd')
16+
expect(Matplotlib.rcParams['path.sketch']).to eq(PyCall.tuple(42, 43, 44))
17+
end
18+
expect(Matplotlib.rcParams['font.family']).to eq(saved_font_family)
19+
expect(Matplotlib.rcParams['path.sketch']).to eq(saved_path_sketch)
20+
end
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)