rubyplot 0.0.1 → 0.1.pre.a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +133 -0
  5. data/.travis.yml +18 -0
  6. data/CHANGELOG.md +9 -0
  7. data/CONTRIBUTING.md +48 -0
  8. data/Gemfile +6 -0
  9. data/README.md +47 -0
  10. data/Rakefile +32 -0
  11. data/ext/grruby/extconf.rb +6 -0
  12. data/ext/grruby/grruby.c +1163 -0
  13. data/ext/grruby/grruby.h +135 -0
  14. data/lib/rubyplot.rb +30 -1
  15. data/lib/rubyplot/artist.rb +13 -0
  16. data/lib/rubyplot/artist/axes.rb +328 -0
  17. data/lib/rubyplot/artist/axis.rb +3 -0
  18. data/lib/rubyplot/artist/axis/base.rb +34 -0
  19. data/lib/rubyplot/artist/axis/x_axis.rb +35 -0
  20. data/lib/rubyplot/artist/axis/y_axis.rb +40 -0
  21. data/lib/rubyplot/artist/base.rb +14 -0
  22. data/lib/rubyplot/artist/circle.rb +28 -0
  23. data/lib/rubyplot/artist/figure.rb +90 -0
  24. data/lib/rubyplot/artist/legend.rb +59 -0
  25. data/lib/rubyplot/artist/legend_box.rb +89 -0
  26. data/lib/rubyplot/artist/line2d.rb +24 -0
  27. data/lib/rubyplot/artist/plot.rb +9 -0
  28. data/lib/rubyplot/artist/plot/area.rb +38 -0
  29. data/lib/rubyplot/artist/plot/bar.rb +69 -0
  30. data/lib/rubyplot/artist/plot/bar_type.rb +31 -0
  31. data/lib/rubyplot/artist/plot/base.rb +67 -0
  32. data/lib/rubyplot/artist/plot/bubble.rb +41 -0
  33. data/lib/rubyplot/artist/plot/line.rb +61 -0
  34. data/lib/rubyplot/artist/plot/multi_bars.rb +75 -0
  35. data/lib/rubyplot/artist/plot/multi_stacked_bar.rb +78 -0
  36. data/lib/rubyplot/artist/plot/scatter.rb +29 -0
  37. data/lib/rubyplot/artist/plot/stacked_bar.rb +69 -0
  38. data/lib/rubyplot/artist/polygon.rb +21 -0
  39. data/lib/rubyplot/artist/rectangle.rb +39 -0
  40. data/lib/rubyplot/artist/text.rb +49 -0
  41. data/lib/rubyplot/artist/tick.rb +3 -0
  42. data/lib/rubyplot/artist/tick/base.rb +35 -0
  43. data/lib/rubyplot/artist/tick/x_tick.rb +25 -0
  44. data/lib/rubyplot/artist/tick/y_tick.rb +24 -0
  45. data/lib/rubyplot/backend.rb +2 -0
  46. data/lib/rubyplot/backend/gr_wrapper.rb +7 -0
  47. data/lib/rubyplot/backend/magick_wrapper.rb +141 -0
  48. data/lib/rubyplot/color.rb +992 -0
  49. data/lib/rubyplot/figure.rb +2 -0
  50. data/lib/rubyplot/spi.rb +8 -0
  51. data/lib/rubyplot/subplot.rb +4 -0
  52. data/lib/rubyplot/themes.rb +47 -0
  53. data/lib/rubyplot/utils.rb +14 -0
  54. data/lib/rubyplot/version.rb +1 -1
  55. data/rubyplot.gemspec +10 -0
  56. data/spec/axes_spec.rb +477 -0
  57. data/spec/figure_spec.rb +12 -0
  58. data/spec/spec_helper.rb +62 -0
  59. data/spec/spi/multi_plot_graph_spec.rb +33 -0
  60. data/spec/spi/single_plot_graph_spec.rb +227 -0
  61. data/spec/spi/subplots_spec.rb +55 -0
  62. metadata +166 -8
@@ -0,0 +1,2 @@
1
+ # Alias meant for easy class initialization without knowing Artist details.
2
+ Rubyplot::Figure = Rubyplot::Artist::Figure
@@ -0,0 +1,8 @@
1
+ module Rubyplot
2
+ # Rubyplot simple plotting interface
3
+ class SPI
4
+ def initialize; end
5
+
6
+ def scatter!(*args, &block); end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Rubyplot
2
+ class Subplot
3
+ end
4
+ end
@@ -0,0 +1,47 @@
1
+ module Rubyplot
2
+ # A set of constants to define themes constant variables
3
+ # to be used to make beautiful looking plots.
4
+ module Themes
5
+ # A color scheme similar to the popular presentation software.
6
+ BASIC = {
7
+ marker_color: 'white', # The color of the marker used to make marker lines on plot.
8
+ font_color: 'white', # Font Color used to write on the plot.
9
+ background_colors: %I[black gun_powder], # The Background colors that form the gradient
10
+ label_colors: %I[lemon bondi_blue sun dark_orchid magic_mint olive sandy_beach navy grey]
11
+ }.freeze
12
+
13
+ TRACKS = {
14
+ marker_color: 'white',
15
+ font_color: 'white',
16
+ background_colors: %I[eastern_blue eastern_blue],
17
+ label_colors: %I[yellow green blue red maroon grey \
18
+ bittersweet light_pink violet bright_turquoise spring_green green_yellow orange misty_rose\
19
+ silver falu_red royal_blue crimson]
20
+
21
+ }.freeze
22
+
23
+ OREO = {
24
+ marker_color: 'white',
25
+ font_color: 'white',
26
+ background_colors: %I[eastern_blue eastern_blue],
27
+ label_colors: %I[crimson fruit_salad lemon bondi_blue sun dark_orchid teal mauve hot_toddy]
28
+ }.freeze
29
+
30
+ RITA = {
31
+ marker_color: 'black',
32
+ font_color: 'black',
33
+ background_colors: %I[pattens_blue white],
34
+ label_colors: %I[turquoise razzle_dazzle_rose pear your_pink teal mauve hot_toddy lemon_chiffon maroon]
35
+ }.freeze
36
+
37
+ # Plain White back ground with no gradient.
38
+ CLASSIC_WHITE = {
39
+ marker_color: 'black',
40
+ font_color: 'black',
41
+ background_colors: %I[white white],
42
+ label_colors: %I[strong_blue vivid_orange dark_lime_green strong_red slightly_desaturated_violet \
43
+ dark_grey strong_yellow strong_cyan yellow maroon grey]
44
+
45
+ }.freeze
46
+ end
47
+ end
@@ -0,0 +1,14 @@
1
+ module Rubyplot
2
+ module Utils
3
+ THOUSAND_SEPARATOR = ','.freeze
4
+ class << self
5
+ def format_label label
6
+ if label.is_a? Numeric
7
+ '%0.2f' % label
8
+ elsif label.is_a? String
9
+ label
10
+ end
11
+ end
12
+ end
13
+ end # module Utils
14
+ end # module Rubyplot
@@ -1,3 +1,3 @@
1
1
  module Rubyplot
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1-a1'.freeze
3
3
  end
@@ -21,4 +21,14 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
23
  spec.require_paths = ["lib"]
24
+ spec.extensions = ['ext/grruby/extconf.rb']
25
+
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rake-compiler'
29
+ spec.add_development_dependency 'rspec'
30
+ spec.add_development_dependency 'pry'
31
+ spec.add_development_dependency 'rubocop'
32
+
33
+ spec.add_runtime_dependency 'rmagick', '>= 2.13.4'
24
34
  end
@@ -0,0 +1,477 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Rubyplot::Axes b: #{Rubyplot.backend}." do
4
+ before do
5
+ @planet_data = [
6
+ ["Moon", [25, 36, 86, 39]],
7
+ ["Sun", [80, 54, 67, 54]],
8
+ ["Earth", [22, 29, 35, 38]],
9
+ ["Mars", [95, 95, 95, 90, 85, 80, 88, 100]],
10
+ ["Venus", [90, 34, 23, 12, 78, 89, 98, 88]]
11
+ ]
12
+ end
13
+
14
+ context "#stacked_bar!" do
15
+ it "plots multiple stacked bar graphs with default colors" do
16
+ @figure = Rubyplot::Figure.new
17
+ axes = @figure.add_subplot 0,0
18
+ [
19
+ ["Charles", [20, 10, 5, 12, 11, 6, 10, 7]],
20
+ ["Adam", [5, 10, 20, 6, 9, 12, 14, 8]],
21
+ ["Daniel", [19, 9, 6, 11, 12, 7, 15, 8]]
22
+ ].each do |label, data|
23
+ axes.stacked_bar! do |p|
24
+ p.data data
25
+ p.label = label
26
+ end
27
+ end
28
+ axes.title = "net earnings in different months."
29
+ axes.x_title = "X title"
30
+ axes.y_title = "Y title"
31
+ axes.x_ticks = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
32
+ 'August', 'September', 'October', 'November', 'December']
33
+ axes.y_ticks = ['5', '10', '15', '20', '25', '30']
34
+ end
35
+
36
+ it "plots stacked bar in a small size" do
37
+ @figure = Rubyplot::Figure.new(height: 400, width: 400)
38
+ axes = @figure.add_subplot 0,0
39
+ [
40
+ ["Car", [25, 36, 86, 39]],
41
+ ["Bus", [80, 54, 67, 54]],
42
+ ["Train", [22, 29, 35, 38]]
43
+ ].each do |label, data|
44
+ axes.stacked_bar! do |p|
45
+ p.data data
46
+ p.label = label
47
+ end
48
+ end
49
+ axes.title = "stacked bar."
50
+ end
51
+ end
52
+
53
+ context "#dot!" do
54
+ skip "plots a single dot plot" do
55
+ @figure = Rubyplot::Figure.new
56
+ axes = @figure.add_subplot 0,0
57
+ axes.dot! do |p|
58
+ p.data [0,5,8,15]
59
+ p.label = "Car"
60
+ p.color = :maroon
61
+ end
62
+ axes.num_y_ticks = 4
63
+ axes.y_ticks = ['5/6', '5/15', '5/24', '5/30']
64
+ end
65
+
66
+ skip "plots multiple dot plots" do
67
+ @figure = Rubyplot::Figure.new
68
+ axes = @figure.add_subplot 0,0
69
+ [
70
+ [[0, 5, 8, 15], "cars", :maroon],
71
+ [[10, 3, 2, 8], "buses", :grey],
72
+ [[2, 15, 8, 11],"science", :yellow]
73
+ ].each do |data, label, color|
74
+ axes.dot! do |p|
75
+ p.data data
76
+ p.label = label
77
+ p.color = color
78
+ p.minimum_value = 0
79
+ end
80
+ end
81
+ axes.num_y_ticks = 4
82
+ axes.y_ticks = ['5/6', '5/15', '5/24', '5/30']
83
+ end
84
+ end
85
+
86
+ context "#bubble!" do
87
+ it "plots a single bubble plot" do
88
+ @figure = Rubyplot::Figure.new
89
+ axes = @figure.add_subplot 0,0
90
+ axes.bubble! do |p|
91
+ p.data [-1, 19, -4, -23], [-35, 21, 23, -4], [45, 10, 21, 9]
92
+ p.label = "apples"
93
+ p.color = :blue
94
+ end
95
+ axes.title = "simple bubble plot."
96
+ end
97
+
98
+ it "plots multiple bubble plots on same axes." do
99
+ @figure = Rubyplot::Figure.new
100
+ axes = @figure.add_subplot 0,0
101
+ axes.bubble! do |p|
102
+ p.data [-1, 19, -4, -23], [-35, 21, 23, -4], [45, 10, 21, 9]
103
+ p.label = "apples"
104
+ end
105
+ axes.bubble! do |p|
106
+ p.data [20, 30, -6, -3], [-1, 5, -27, -3], [13, 10, 20, 10]
107
+ p.label = "peaches"
108
+ end
109
+ axes.title = "simple bubble plot."
110
+ end
111
+ end
112
+
113
+ context "#area!" do
114
+ it "plots a single simple Area graph" do
115
+ @figure = Rubyplot::Figure.new
116
+ axes = @figure.add_subplot 0,0
117
+ axes.area! do |p|
118
+ p.data [25, 36, 86, 39, 25, 31, 79, 88]
119
+ p.label = "Jimmy"
120
+ end
121
+ axes.title = "Visual simple area graph test."
122
+ axes.num_x_ticks = 5
123
+ axes.x_ticks = ['0', '22', '44', '66', '88']
124
+ end
125
+
126
+ it "plots multiple area plots on the same Axes" do
127
+ @figure = Rubyplot::Figure.new
128
+ axes = @figure.add_subplot 0,0
129
+ [
130
+ ["Jimmy", [25, 36, 86, 39, 25, 31, 79, 88]],
131
+ ["Charles", [80, 54, 67, 54, 68, 70, 90, 95]],
132
+ ["Julie", [22, 29, 35, 38, 36, 40, 46, 57]],
133
+ ["Jane", [3, 95, 95, 90, 85, 80, 88, 100]]
134
+ ].each do |n, data|
135
+ axes.area! do |p|
136
+ p.data data
137
+ p.label = n
138
+ end
139
+ end
140
+ axes.title = "Multiple area plots on same axes."
141
+ axes.num_x_ticks = 4
142
+ axes.x_ticks = ['0', '2', '4', '6']
143
+ end
144
+ end
145
+
146
+ context "#line!" do
147
+ it "makes a simple line plot" do
148
+ @figure = Rubyplot::Figure.new
149
+ axes = @figure.add_subplot 0,0
150
+ axes.line! do |p|
151
+ p.data [2, 4, 7, 9], [1,2,3,4]
152
+ p.label = "Marco"
153
+ p.color = :blue
154
+ end
155
+ axes.title = "A line graph."
156
+ end
157
+
158
+ it "plots 2 simple lines on the same axes" do
159
+ @figure = Rubyplot::Figure.new
160
+ axes = @figure.add_subplot 0,0
161
+ axes.line! do |p|
162
+ p.data [3, 5, 10, 15]
163
+ p.label = "Marco"
164
+ p.color = :blue
165
+ end
166
+ axes.line! do |p|
167
+ p.data [1, 9, 13, 28]
168
+ p.label = "John"
169
+ p.color = :green
170
+ end
171
+ axes.title = "A line graph."
172
+ end
173
+
174
+ it "tests very small plot" do
175
+ @figure = Rubyplot::Figure.new
176
+ axes = @figure.add_subplot 0,0
177
+ axes.title = "very small line chart 200px"
178
+ @planet_data.each do |name, d|
179
+ axes.line! do |p|
180
+ p.data d
181
+ p.label = name
182
+ end
183
+ end
184
+ end
185
+
186
+ it "plots multiple 0 data" do
187
+ @figure = Rubyplot::Figure.new
188
+ axes = @figure.add_subplot 0,0
189
+ axes.title = "hand value graph test"
190
+ axes.line! do |p|
191
+ p.data [0,0,100]
192
+ p.label = "test"
193
+ end
194
+ end
195
+
196
+ it "plots small values" do
197
+ @figure = Rubyplot::Figure.new
198
+ axes = @figure.add_subplot 0,0
199
+ axes.title = "small values"
200
+ [
201
+ [[0.1, 0.14356, 0.0, 0.5674839, 0.456], "small"],
202
+ [[0.2, 0.3, 0.1, 0.05, 0.9], "small2"]
203
+ ].each do |d, label|
204
+ axes.line! do |p|
205
+ p.data d
206
+ p.label = label
207
+ end
208
+ end
209
+ end
210
+
211
+ it "plots line starting with 0" do
212
+ @figure = Rubyplot::Figure.new
213
+ axes = @figure.add_subplot 0,0
214
+ axes.title = "starting with 0"
215
+ [
216
+ [[0, 5, 10, 8, 18], "first0"],
217
+ [[1, 2, 3, 4, 5], "normal"]
218
+ ].each do |data, name|
219
+ axes.line! do |p|
220
+ p.data data
221
+ p.label = name
222
+ end
223
+ end
224
+ end
225
+
226
+ it "plots line with large values" do
227
+ @figure = Rubyplot::Figure.new
228
+ axes = @figure.add_subplot 0,0
229
+ axes.title = "large values"
230
+ [
231
+ ["large", [100_005, 35_000, 28_000, 27_000]],
232
+ ["large2", [35_000, 28_000, 27_000, 100_005]],
233
+ ["large3", [28_000, 27_000, 100_005, 35_000]],
234
+ ["large4", [1_238, 39_092, 27_938, 48_876]]
235
+ ].each do |name, data|
236
+ axes.line! do |p|
237
+ p.line_width = 3
238
+ p.data data
239
+ p.label = name
240
+ end
241
+ end
242
+ end
243
+
244
+ it "accepts both X and Y data" do
245
+ @figure = Rubyplot::Figure.new
246
+ axes = @figure.add_subplot 0,0
247
+ axes.title = "accept X and Y"
248
+ axes.line! do |p|
249
+ p.data [1, 3, 4, 5, 6, 10], [1, 2, 3, 4, 4, 3]
250
+ p.label = "X"
251
+ end
252
+ axes.line! do |p|
253
+ p.data [1, 3, 4, 5, 7, 9], [1, 1, 2, 2, 3, 3]
254
+ p.label = "X1"
255
+ end
256
+ end
257
+ end
258
+
259
+ context "#bar!" do
260
+ it "adds a simple bar plot" do
261
+ @figure = Rubyplot::Figure.new
262
+ axes = @figure.add_subplot 0,0
263
+ axes.bar! do |p|
264
+ p.data [5,12,9,6,7]
265
+ p.label = "data"
266
+ p.color = :yellow
267
+ end
268
+ axes.x_ticks = ["five", "twelve", "nine", "six", "seven"]
269
+ axes.title = "Random bar numbers"
270
+ end
271
+
272
+ it "adds bar plot with title margin" do
273
+ @figure = Rubyplot::Figure.new
274
+ axes = @figure.add_subplot 0,0
275
+ axes.bar! do |p|
276
+ p.data [5,12,9,6,6]
277
+ p.label = "data"
278
+ p.color = :green
279
+ end
280
+ axes.title = "Bar with title margin = 100"
281
+ end
282
+
283
+ it "plots large numbers" do
284
+ @figure = Rubyplot::Figure.new
285
+ axes = @figure.add_subplot 0,0
286
+ axes.bar! do |p|
287
+ p.data [7025, 1024, 40_257, 933_672, 1_560_496]
288
+ p.label = "data"
289
+ end
290
+ axes.title = "Large numbers"
291
+ end
292
+
293
+ it "adds axes with X-Y labels" do
294
+ @figure = Rubyplot::Figure.new
295
+ axes = @figure.add_subplot 0,0
296
+ axes.bar! do |p|
297
+ p.data [40,50,60,80]
298
+ p.label = "students"
299
+ end
300
+ axes.title = "Plot with X-Y axes."
301
+ axes.x_title = "Students"
302
+ axes.y_title = "Score (%)"
303
+ axes.x_ticks = [ '5/6', '5/15', '5/24', '5/36' ]
304
+ end
305
+
306
+ it "adds multiple bar plots for wide graph" do
307
+ @figure = Rubyplot::Figure.new(height: 400, width: 800)
308
+ axes = @figure.add_subplot 0,0
309
+ @planet_data.each do |name, nums|
310
+ axes.bar! do |p|
311
+ p.data nums
312
+ p.label = name
313
+ end
314
+ end
315
+ end
316
+
317
+ it "plots both positive and negative values" do
318
+ @figure = Rubyplot::Figure.new
319
+ axes = @figure.add_subplot 0,0
320
+ axes.bar! do |p|
321
+ p.data [-1, 0, 4, -4]
322
+ p.label = "apples"
323
+ end
324
+ axes.bar! do |p|
325
+ p.data [10,8,6,3]
326
+ p.label = "peaches"
327
+ end
328
+ axes.title = "Pos/neg bar graph test."
329
+ axes.x_ticks = ['5/6', '5/15', '5/24', '5/30']
330
+ end
331
+
332
+ it "tests negative values" do
333
+ @figure = Rubyplot::Figure.new
334
+ axes = @figure.add_subplot 0,0
335
+ axes.title = "all negative bar graph."
336
+ axes.x_ticks = ['5/6', '5/15', '5/24', '5/30']
337
+ axes.bar! do |p|
338
+ p.data [-1,-5,-4,-4]
339
+ p.label = "apples"
340
+ end
341
+ axes.bar! do |p|
342
+ p.data [-10,-8,-6,-3]
343
+ p.label = "peaches"
344
+ end
345
+ end
346
+
347
+ it "sets min-max range for Y axis" do
348
+ @figure = Rubyplot::Figure.new
349
+ axes = @figure.add_subplot 0,0
350
+ axes.title = "nearly zero graph."
351
+ axes.y_range = [0,10]
352
+ [
353
+ [[1,2,3,4], "apples"],
354
+ [[4,3,2,1], "peaches"]
355
+ ].each do |nums, name|
356
+ axes.bar! do |p|
357
+ p.data nums
358
+ p.label = name
359
+ end
360
+ end
361
+ axes.x_ticks = ['5/6', '5/15', '5/24','5/30']
362
+ end
363
+
364
+ it "adjust legends if there are too many" do
365
+ @figure = Rubyplot::Figure.new
366
+ axes = @figure.add_subplot 0,0
367
+ axes.title = "My graph."
368
+ [
369
+ [[1, 2, 3, 4, 4, 3], 'Apples oranges Watermelon'],
370
+ [[4, 8, 7, 9, 8, 9], "Oranges"],
371
+ [[2, 3, 1, 5, 6, 8], "Watermelon"],
372
+ [[9, 9, 10, 8, 7, 9], "Peaches"]
373
+ ].each do |d, name|
374
+ axes.bar! do |p|
375
+ p.data d
376
+ p.label = name
377
+ end
378
+ end
379
+ axes.x_ticks = ['2003', '', '2004', '', '2005']
380
+ end
381
+ end
382
+
383
+ context "#scatter!" do
384
+ before do
385
+ @x1 = [1, 2, 3, 4, 5]
386
+ @y1 = [11, 2, 33, 4, 65]
387
+ end
388
+
389
+ it "adds a simple scatter plot." do
390
+ @figure = Rubyplot::Figure.new
391
+ axes = @figure.add_subplot 0,0
392
+ axes.scatter! do |p|
393
+ p.data @x1, @y1
394
+ p.label = "data1"
395
+ p.color = :plum_purple
396
+ end
397
+ axes.title = "Nice plot"
398
+ axes.x_title = "X data"
399
+ axes.y_title = "Y data"
400
+ end
401
+
402
+ it "adds scatter with all negative values" do
403
+ @figure = Rubyplot::Figure.new
404
+ axes = @figure.add_subplot 0,0
405
+ axes.scatter! do |p|
406
+ p.data [-1, -1, -4, -4], [-5, -1, -3, -4]
407
+ p.label = "apples"
408
+ end
409
+ axes.title = "all negative scatter graph test."
410
+ end
411
+
412
+ it "adds scatter with positive and negative values" do
413
+ @figure = Rubyplot::Figure.new
414
+ axes = @figure.add_subplot 0,0
415
+ axes.scatter! do |p|
416
+ p.data [-2,0,2,4,6], [-3,-1, 1, 4, 8]
417
+ p.label = "values"
418
+ end
419
+ axes.title = "positive + negative test."
420
+ end
421
+ end
422
+
423
+ context "#top_margin=" do
424
+ it "sets the top margin in pixels" do
425
+
426
+ end
427
+ end
428
+
429
+ context "#left_margin=" do
430
+ it "sets the left margin in pixels" do
431
+
432
+ end
433
+ end
434
+
435
+ context "#bottom_margin=" do
436
+ it "sets the bottom margin in pixels" do
437
+
438
+ end
439
+ end
440
+
441
+ context "#right_margin=" do
442
+ it "sets the right margin in pixels" do
443
+
444
+ end
445
+ end
446
+
447
+ context "#num_x_ticks=" do
448
+ it "assigns number of X ticks" do
449
+ fig = Rubyplot::Figure.new
450
+ axes = fig.add_subplot 0,0
451
+ axes.scatter! do |p|
452
+ p.data [0,1,2,3], [4, 7, 11, 15]
453
+ end
454
+ axes.num_x_ticks = 3
455
+ axes.x_ticks = ["4", "10", "15"]
456
+ fig.write("dummy.png", output: false)
457
+
458
+ expect(
459
+ axes.instance_variable_get(:@inter_x_ticks_distance)).to eq(
460
+ axes.x_axis.length /
461
+ (axes.num_x_ticks-1))
462
+ end
463
+ end
464
+
465
+ context "#x_ticks=" do
466
+ it "assigns strings to X ticks" do
467
+ @figure = Rubyplot::Figure.new
468
+ axes = @figure.add_subplot 0,0
469
+ axes.scatter! do |p|
470
+ p.data [1,2,3,4], [1,2,3,4]
471
+ p.label = "apples"
472
+ end
473
+ axes.x_ticks = ["hello0", "hello1"]
474
+ end
475
+ end # context "#x_ticks="
476
+ end # Rubyplot::Axes
477
+