summaryrefslogtreecommitdiff
path: root/python-mpl-plotter.spec
blob: 27557d26595e7384b4fc9c53a4d66238f5493780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
%global _empty_manifest_terminate_build 0
Name:		python-mpl-plotter
Version:	5.5.0
Release:	1
Summary:	Publication-quality data representation library based on Matplotlib.
License:	GNU General Public License v3 (GPLv3)
URL:		https://github.com/alopezrivera/mpl_plotter
Source0:	https://mirrors.aliyun.com/pypi/web/packages/de/5b/690e2f94f224b27f7315197770311fe07895a9128d50035a429e760d6949/mpl_plotter-5.5.0.tar.gz
BuildArch:	noarch


%description
Two more examples (results in the table below):
1. We can add some customization to make our line look a bit better:
        line(show=True, pad_demo=True, spines_removed=None)
    Our line has now some margins to breathe while the ticks are placed at the maximum and minimums of our curve, 
    and no spines are removed.
2. Lastly, an example using some of the parameters you can change:
        line(norm=True, line_width=4,
             title="Custom Line", title_font="Pump Triline", title_size=40, title_color="orange",
             label_x="x", label_y="$\Psi$",
             label_size_x=30, label_size_y=20,
             label_pad_x=-0.05, label_pad_y=10,
             label_rotation_y=0,
             aspect=1,
             pad_demo=True,
             workspace_color="darkred",
             grid=True, grid_color="grey",
             tick_color="darkgrey", tick_decimals=4,
             tick_number_x=12, tick_number_y=12,
             tick_rotation_x=35,
             color_bar=True, cb_tick_number=5, cb_pad=0.05,
             show=True)
| [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L13) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L21) |
| --- | --- |
| ![alt text](demo/gallery/2d/medium_line.png "Some customization") | ![alt text](demo/gallery/2d/custom_line.png "Showcase") |
### 4.2 3D
Same applies in 3D.
| [0](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L5) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L15) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L31) |
|---|---|---|
|![alt text](demo/gallery/3d/basic_line.png "Basic")|![alt text](demo/gallery/3d/medium_line.png "Some customization")|![alt text](demo/gallery/3d/custom_line.png "Showcase")|
# 5. Curve comparisons and multiple pane plots
`from mpl_plotter.two_d import comparison, panes`
### 5.1 `comparison`
Plot any number of curves in a single plot. Axis limits will be set to the maximum and minimum of all your curves. 
No data will be left out, among other niceties.
#### Data input
Inputs must match (2 `x`s and 3 `y`s won't work), BUT the following inputs are all valid:
|   x                      |   y                       |  result  |  notes               |
|  ---                     |  ---                      |  ---     |  ---                 |
|  array                   |  array                    |  1       |                      |
|  array                   |  [array, array]           |  2       |  Both `y`s share `x` |
|  [array, array]          |  [array, array]           |  2       |  Each `y` has an `x` |
|  [n*[array]]             |  [n*[array]]              |  n       |  Each `y` has an `x` |
#### Plotting methods
You can specify **different plotting methods for each curve in the plot**, a custom one for all curves, 
or not specify any (defaulting to lines). How? Check the code block below. 
This is nice as it allows you to crisply combine lines, scatter plots and any other of the MPL Plotter
plotting methods.
#### Other arguments
As to any and all other arguments:
- **Singular arguments**: the regular MPL Plotter plotting class arguments. Apply to all curves in the plot.
- **Plural arguments**: pass a list of arguments, one for each curve. The result is as you'd imagine.
```
from mpl_plotter.two_d import comparison, line, scatter
def f(x, y, **kwargs):
    line(x, y,
         line_width=2,
         **kwargs)
def g(x, y, **kwargs):
    scatter(x, y,
            marker="D",
            point_size=10,
            **kwargs)
def h(x, y, **kwargs):
    scatter(x, y,
            marker="s",
            point_size=5,
            **kwargs)
comparison([x, x, x],
           [u, v, w],
           [f, g, h],
           plot_labels=["sin", "cos", "tan"],
           zorders=[1, 2, 3],
           colors=['C1', 'C2', 'C3'],
           alphas=[0.5, 0.5, 1],
           x_custom_tick_labels=[0, r"$\frac{\pi}{8}$", r"$\frac{\pi}{4}$"],
           show=show, backend=backend
           )
```
![alt text](demo/gallery/2d/comparison_custom.png "Curve comparison")
### 5.2 `panes`
The panes function allows for the plotting of a series of graphs in side-by-side panes. As to data input, the table below applies. 
It uses the `comparison`, function under the hood so the same input guidelines apply for all other inputs.
|   x                              |   y                               |  result  |  notes                                          |
|  ---                             |  ---                              |  ---     |  ---                                            |
|  array                           |  array                            |  11      |                                                 |
|  array                           |  [array, array]                   |  12      |  Both `y`s share `x`                            |
|  [n*[array]]                     |  [n*[array]]                      |  1n      |  Each `y` has an `x`                            |
|  array                           |  [array, array]                   |  21      |  Both `y`s share `x`                            |
|  [array, array]                  |  [array, array]                   |  21      |  Each `y` has an `x`                            |
|  array                           |  [n*[array], n*[array]]           |  2n      |  All curves in all (2) panes share a single `x` |
|  [array, array]                  |  [n*[array], n*[array]]           |  2n      |  All curves in each pane share an `x`           |
|  [n*[array], n*[array]]          |  [n*[array], n*[array]]           |  2n      |  All curves in all (2) panes have their own `x` |
|  [n*[array], ... up to m]        |  [n*[array], ... up to m]         |  mn      |  All curves in all panes have their own `x`     |
### Code
The following plots one curve per pane (3 in total):
```
panes(x,                   # Horizontal vector
      [u, v, y],           # List of curves to be plotted
      ["u", "v", "y"],     # List of vertical axis labels
      ["a", "b", "c"]      # List of legend labels 
      )
```
![alt text](demo/gallery/2d/pane_single.png "Single-curve panes")
And the following plots an arbitrary number of curves per pane. As you can see, you just need to input 
`n` **lists** of `m` curves (where `m`=2 in the example below), and you will get a plot with `n` panes, with `m`
curves in each.
```
panes(x,                               # Horizontal vector
      [[u, uu], [v, vv], [y, yy]],     # List of pairs of curves to be compared
      ["u", "v", "y"],                 # List of vertical axis labels
      ["a", "b"]                       # List of legend labels
      )
```
![alt text](demo/gallery/2d/pane_comparison.png "Multiple-curve comparison panes")
### Demo
Preposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is
available in `tests/test_panes.py`.
![alt text](demo/gallery/2d/pane_alot.png "There's a lot")
![alt text](demo/gallery/2d/pane_alot_comparison.png "Lots of triplets") 
# 6. Presets
TL;DR: Take a parameter `toml` and forget about function inputs.
### 6.1 Standard presets
Standard presets are available to remove overhead. They're tailored for my use cases but you may find them useful anyway.
| ![alt text](demo/gallery/2d/preset_publication_scatter.png "Publication preset")| ![alt text](demo/gallery/2d/preset_publication_heatmap.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_quiver.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_streamline.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_fill.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_line.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_scatter.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_surface.png "Publication preset") |
| --- | --- | --- | --- | --- | --- | --- | --- |
| ![alt text](demo/gallery/2d/preset_precision_scatter.png "Precision preset")| ![alt text](demo/gallery/2d/preset_precision_heatmap.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_quiver.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_streamline.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_fill.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_line.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_scatter.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_surface.png "Precision preset") | 
#### _Publication_
It is a common mistake to make a figure for a paper with unreadable labels. This preset tries to solve that, 
generating plots optimized to be printed on a small format, in side-by-side plots or embedded in a column of text.
    from mpl_plotter.presets.precision import two_d
    from mpl_plotter.color.schemes import one           # Custom colorscheme
    x = np.linspace(0, 4, 1000)
    y = np.exp(x)
    z = abs(np.sin(x)*np.exp(x))
    two_d.line(x, z, aspect=0.05, color=one()[-2], show=True)
![alt text](demo/gallery/2d/preset_publication_line.png "Publication preset")
#### _Precision_
Made to plot functions large on the screen, with equal x and y scales to avoid skewing the variables, and 
many ticks to visually inspect a signal.
    from mpl_plotter.presets.precision import two_d
    two_d.line(x, z, aspect=0.05, color=one()[-2], show=True)
![alt text](demo/gallery/2d/preset_precision_line.png "Precision preset")
### 6.2 Custom presets
Example workflow follows. For further reference check [the preset tests](https://github.com/alopezrivera/mpl_plotter/blob/master/tests/test_presets.py).
1. Import the preset creation function
      ```
      from mpl_plotter.presets import preset
      ```
2. Create a preset, either from a plotter,
      ```
      from mpl_plotter.two_d import line
      _preset = preset(line)
      ```
   or from a dimension. In this case, the preset will contain all common parameters to all plots
   in 2 or 3 dimensions.
      ```
      _preset = preset(dim=2)
      ```
   The preset is a dictionary. You can edit its parameters as you would expect. However, it is more convenient to
3. Save your preset in a `toml` file. This will yield you a `toml` file containing all parameters for your plot or dimension, allowing you to easily inspect defaults and tailor settings to your liking. You may edit this file as you please, as long as you do not infringe on its syntax.
      ```
      _preset.save('tests/presets/test.toml')
      ```
4. Load the file in the same -or a different session.
      ```
      from mpl_plotter.presets import preset
      _preset = preset.load('tests/presets/test.toml')
      ```
5. Import an MPL Plotter preset plotter and load it with your preset
      ```
      from mpl_plotter.presets import two_d
      _two_d = two_d(preset=_preset)
      ```
6. Plot as you wish
      ```
      _two_d.line(show=True)
      _two_d.scatter(show=True)
      _two_d.<...>
      ```
# 7. Matplotlib
### 7.1 Retrieving axes, figures
The axis and figure on which each class draws are instance attributes. To retrieve them and continue modifications 
using standard Matplotlib:
    from mpl_plotter.two_d import line
    my_plot = line()
    ax, fig = my_plot.ax, my_plot.fig
With the axis and figure, most Matplotlib functions out there can be used to further modify your plots. 
### 7.2 Using Matplotlib's axis tiling
Matplotlib allows for subplot composition using `subplot2grid`. This can be used in combination with MPL Plotter:
Importantly:
- The auxiliary function `figure` (`from mpl_plotter figure`) sets up a figure in a chosen backend. 
This is convenient, as if the figure is created with `plt.figure()`, only the default non-interactive Matplotlib 
backend will be available, unless `matplotlib.use(<backend>)` is specified before importing `pyplot`.
```
from mpl_plotter import figure
from mpl_plotter.two_d import line, quiver, streamline, fill_area
backend = "Qt5Agg"  # None -> regular non-interactive matplotlib output
figure(figsize=(10, 10), backend=backend)
ax0 = plt.subplot2grid((2, 2), (0, 0), rowspan=1)
ax1 = plt.subplot2grid((2, 2), (1, 0), rowspan=1)
ax2 = plt.subplot2grid((2, 2), (0, 1), rowspan=1)
ax3 = plt.subplot2grid((2, 2), (1, 1), rowspan=1)
axes = [ax0, ax1, ax2, ax3]
plots = [line, quiver, streamline, fill_area]
for i in range(len(plots)):
    plots[i](ax=axes[i])
plt.show()
```

%package -n python3-mpl-plotter
Summary:	Publication-quality data representation library based on Matplotlib.
Provides:	python-mpl-plotter
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-mpl-plotter
Two more examples (results in the table below):
1. We can add some customization to make our line look a bit better:
        line(show=True, pad_demo=True, spines_removed=None)
    Our line has now some margins to breathe while the ticks are placed at the maximum and minimums of our curve, 
    and no spines are removed.
2. Lastly, an example using some of the parameters you can change:
        line(norm=True, line_width=4,
             title="Custom Line", title_font="Pump Triline", title_size=40, title_color="orange",
             label_x="x", label_y="$\Psi$",
             label_size_x=30, label_size_y=20,
             label_pad_x=-0.05, label_pad_y=10,
             label_rotation_y=0,
             aspect=1,
             pad_demo=True,
             workspace_color="darkred",
             grid=True, grid_color="grey",
             tick_color="darkgrey", tick_decimals=4,
             tick_number_x=12, tick_number_y=12,
             tick_rotation_x=35,
             color_bar=True, cb_tick_number=5, cb_pad=0.05,
             show=True)
| [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L13) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L21) |
| --- | --- |
| ![alt text](demo/gallery/2d/medium_line.png "Some customization") | ![alt text](demo/gallery/2d/custom_line.png "Showcase") |
### 4.2 3D
Same applies in 3D.
| [0](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L5) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L15) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L31) |
|---|---|---|
|![alt text](demo/gallery/3d/basic_line.png "Basic")|![alt text](demo/gallery/3d/medium_line.png "Some customization")|![alt text](demo/gallery/3d/custom_line.png "Showcase")|
# 5. Curve comparisons and multiple pane plots
`from mpl_plotter.two_d import comparison, panes`
### 5.1 `comparison`
Plot any number of curves in a single plot. Axis limits will be set to the maximum and minimum of all your curves. 
No data will be left out, among other niceties.
#### Data input
Inputs must match (2 `x`s and 3 `y`s won't work), BUT the following inputs are all valid:
|   x                      |   y                       |  result  |  notes               |
|  ---                     |  ---                      |  ---     |  ---                 |
|  array                   |  array                    |  1       |                      |
|  array                   |  [array, array]           |  2       |  Both `y`s share `x` |
|  [array, array]          |  [array, array]           |  2       |  Each `y` has an `x` |
|  [n*[array]]             |  [n*[array]]              |  n       |  Each `y` has an `x` |
#### Plotting methods
You can specify **different plotting methods for each curve in the plot**, a custom one for all curves, 
or not specify any (defaulting to lines). How? Check the code block below. 
This is nice as it allows you to crisply combine lines, scatter plots and any other of the MPL Plotter
plotting methods.
#### Other arguments
As to any and all other arguments:
- **Singular arguments**: the regular MPL Plotter plotting class arguments. Apply to all curves in the plot.
- **Plural arguments**: pass a list of arguments, one for each curve. The result is as you'd imagine.
```
from mpl_plotter.two_d import comparison, line, scatter
def f(x, y, **kwargs):
    line(x, y,
         line_width=2,
         **kwargs)
def g(x, y, **kwargs):
    scatter(x, y,
            marker="D",
            point_size=10,
            **kwargs)
def h(x, y, **kwargs):
    scatter(x, y,
            marker="s",
            point_size=5,
            **kwargs)
comparison([x, x, x],
           [u, v, w],
           [f, g, h],
           plot_labels=["sin", "cos", "tan"],
           zorders=[1, 2, 3],
           colors=['C1', 'C2', 'C3'],
           alphas=[0.5, 0.5, 1],
           x_custom_tick_labels=[0, r"$\frac{\pi}{8}$", r"$\frac{\pi}{4}$"],
           show=show, backend=backend
           )
```
![alt text](demo/gallery/2d/comparison_custom.png "Curve comparison")
### 5.2 `panes`
The panes function allows for the plotting of a series of graphs in side-by-side panes. As to data input, the table below applies. 
It uses the `comparison`, function under the hood so the same input guidelines apply for all other inputs.
|   x                              |   y                               |  result  |  notes                                          |
|  ---                             |  ---                              |  ---     |  ---                                            |
|  array                           |  array                            |  11      |                                                 |
|  array                           |  [array, array]                   |  12      |  Both `y`s share `x`                            |
|  [n*[array]]                     |  [n*[array]]                      |  1n      |  Each `y` has an `x`                            |
|  array                           |  [array, array]                   |  21      |  Both `y`s share `x`                            |
|  [array, array]                  |  [array, array]                   |  21      |  Each `y` has an `x`                            |
|  array                           |  [n*[array], n*[array]]           |  2n      |  All curves in all (2) panes share a single `x` |
|  [array, array]                  |  [n*[array], n*[array]]           |  2n      |  All curves in each pane share an `x`           |
|  [n*[array], n*[array]]          |  [n*[array], n*[array]]           |  2n      |  All curves in all (2) panes have their own `x` |
|  [n*[array], ... up to m]        |  [n*[array], ... up to m]         |  mn      |  All curves in all panes have their own `x`     |
### Code
The following plots one curve per pane (3 in total):
```
panes(x,                   # Horizontal vector
      [u, v, y],           # List of curves to be plotted
      ["u", "v", "y"],     # List of vertical axis labels
      ["a", "b", "c"]      # List of legend labels 
      )
```
![alt text](demo/gallery/2d/pane_single.png "Single-curve panes")
And the following plots an arbitrary number of curves per pane. As you can see, you just need to input 
`n` **lists** of `m` curves (where `m`=2 in the example below), and you will get a plot with `n` panes, with `m`
curves in each.
```
panes(x,                               # Horizontal vector
      [[u, uu], [v, vv], [y, yy]],     # List of pairs of curves to be compared
      ["u", "v", "y"],                 # List of vertical axis labels
      ["a", "b"]                       # List of legend labels
      )
```
![alt text](demo/gallery/2d/pane_comparison.png "Multiple-curve comparison panes")
### Demo
Preposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is
available in `tests/test_panes.py`.
![alt text](demo/gallery/2d/pane_alot.png "There's a lot")
![alt text](demo/gallery/2d/pane_alot_comparison.png "Lots of triplets") 
# 6. Presets
TL;DR: Take a parameter `toml` and forget about function inputs.
### 6.1 Standard presets
Standard presets are available to remove overhead. They're tailored for my use cases but you may find them useful anyway.
| ![alt text](demo/gallery/2d/preset_publication_scatter.png "Publication preset")| ![alt text](demo/gallery/2d/preset_publication_heatmap.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_quiver.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_streamline.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_fill.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_line.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_scatter.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_surface.png "Publication preset") |
| --- | --- | --- | --- | --- | --- | --- | --- |
| ![alt text](demo/gallery/2d/preset_precision_scatter.png "Precision preset")| ![alt text](demo/gallery/2d/preset_precision_heatmap.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_quiver.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_streamline.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_fill.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_line.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_scatter.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_surface.png "Precision preset") | 
#### _Publication_
It is a common mistake to make a figure for a paper with unreadable labels. This preset tries to solve that, 
generating plots optimized to be printed on a small format, in side-by-side plots or embedded in a column of text.
    from mpl_plotter.presets.precision import two_d
    from mpl_plotter.color.schemes import one           # Custom colorscheme
    x = np.linspace(0, 4, 1000)
    y = np.exp(x)
    z = abs(np.sin(x)*np.exp(x))
    two_d.line(x, z, aspect=0.05, color=one()[-2], show=True)
![alt text](demo/gallery/2d/preset_publication_line.png "Publication preset")
#### _Precision_
Made to plot functions large on the screen, with equal x and y scales to avoid skewing the variables, and 
many ticks to visually inspect a signal.
    from mpl_plotter.presets.precision import two_d
    two_d.line(x, z, aspect=0.05, color=one()[-2], show=True)
![alt text](demo/gallery/2d/preset_precision_line.png "Precision preset")
### 6.2 Custom presets
Example workflow follows. For further reference check [the preset tests](https://github.com/alopezrivera/mpl_plotter/blob/master/tests/test_presets.py).
1. Import the preset creation function
      ```
      from mpl_plotter.presets import preset
      ```
2. Create a preset, either from a plotter,
      ```
      from mpl_plotter.two_d import line
      _preset = preset(line)
      ```
   or from a dimension. In this case, the preset will contain all common parameters to all plots
   in 2 or 3 dimensions.
      ```
      _preset = preset(dim=2)
      ```
   The preset is a dictionary. You can edit its parameters as you would expect. However, it is more convenient to
3. Save your preset in a `toml` file. This will yield you a `toml` file containing all parameters for your plot or dimension, allowing you to easily inspect defaults and tailor settings to your liking. You may edit this file as you please, as long as you do not infringe on its syntax.
      ```
      _preset.save('tests/presets/test.toml')
      ```
4. Load the file in the same -or a different session.
      ```
      from mpl_plotter.presets import preset
      _preset = preset.load('tests/presets/test.toml')
      ```
5. Import an MPL Plotter preset plotter and load it with your preset
      ```
      from mpl_plotter.presets import two_d
      _two_d = two_d(preset=_preset)
      ```
6. Plot as you wish
      ```
      _two_d.line(show=True)
      _two_d.scatter(show=True)
      _two_d.<...>
      ```
# 7. Matplotlib
### 7.1 Retrieving axes, figures
The axis and figure on which each class draws are instance attributes. To retrieve them and continue modifications 
using standard Matplotlib:
    from mpl_plotter.two_d import line
    my_plot = line()
    ax, fig = my_plot.ax, my_plot.fig
With the axis and figure, most Matplotlib functions out there can be used to further modify your plots. 
### 7.2 Using Matplotlib's axis tiling
Matplotlib allows for subplot composition using `subplot2grid`. This can be used in combination with MPL Plotter:
Importantly:
- The auxiliary function `figure` (`from mpl_plotter figure`) sets up a figure in a chosen backend. 
This is convenient, as if the figure is created with `plt.figure()`, only the default non-interactive Matplotlib 
backend will be available, unless `matplotlib.use(<backend>)` is specified before importing `pyplot`.
```
from mpl_plotter import figure
from mpl_plotter.two_d import line, quiver, streamline, fill_area
backend = "Qt5Agg"  # None -> regular non-interactive matplotlib output
figure(figsize=(10, 10), backend=backend)
ax0 = plt.subplot2grid((2, 2), (0, 0), rowspan=1)
ax1 = plt.subplot2grid((2, 2), (1, 0), rowspan=1)
ax2 = plt.subplot2grid((2, 2), (0, 1), rowspan=1)
ax3 = plt.subplot2grid((2, 2), (1, 1), rowspan=1)
axes = [ax0, ax1, ax2, ax3]
plots = [line, quiver, streamline, fill_area]
for i in range(len(plots)):
    plots[i](ax=axes[i])
plt.show()
```

%package help
Summary:	Development documents and examples for mpl-plotter
Provides:	python3-mpl-plotter-doc
%description help
Two more examples (results in the table below):
1. We can add some customization to make our line look a bit better:
        line(show=True, pad_demo=True, spines_removed=None)
    Our line has now some margins to breathe while the ticks are placed at the maximum and minimums of our curve, 
    and no spines are removed.
2. Lastly, an example using some of the parameters you can change:
        line(norm=True, line_width=4,
             title="Custom Line", title_font="Pump Triline", title_size=40, title_color="orange",
             label_x="x", label_y="$\Psi$",
             label_size_x=30, label_size_y=20,
             label_pad_x=-0.05, label_pad_y=10,
             label_rotation_y=0,
             aspect=1,
             pad_demo=True,
             workspace_color="darkred",
             grid=True, grid_color="grey",
             tick_color="darkgrey", tick_decimals=4,
             tick_number_x=12, tick_number_y=12,
             tick_rotation_x=35,
             color_bar=True, cb_tick_number=5, cb_pad=0.05,
             show=True)
| [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L13) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L21) |
| --- | --- |
| ![alt text](demo/gallery/2d/medium_line.png "Some customization") | ![alt text](demo/gallery/2d/custom_line.png "Showcase") |
### 4.2 3D
Same applies in 3D.
| [0](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L5) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L15) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L31) |
|---|---|---|
|![alt text](demo/gallery/3d/basic_line.png "Basic")|![alt text](demo/gallery/3d/medium_line.png "Some customization")|![alt text](demo/gallery/3d/custom_line.png "Showcase")|
# 5. Curve comparisons and multiple pane plots
`from mpl_plotter.two_d import comparison, panes`
### 5.1 `comparison`
Plot any number of curves in a single plot. Axis limits will be set to the maximum and minimum of all your curves. 
No data will be left out, among other niceties.
#### Data input
Inputs must match (2 `x`s and 3 `y`s won't work), BUT the following inputs are all valid:
|   x                      |   y                       |  result  |  notes               |
|  ---                     |  ---                      |  ---     |  ---                 |
|  array                   |  array                    |  1       |                      |
|  array                   |  [array, array]           |  2       |  Both `y`s share `x` |
|  [array, array]          |  [array, array]           |  2       |  Each `y` has an `x` |
|  [n*[array]]             |  [n*[array]]              |  n       |  Each `y` has an `x` |
#### Plotting methods
You can specify **different plotting methods for each curve in the plot**, a custom one for all curves, 
or not specify any (defaulting to lines). How? Check the code block below. 
This is nice as it allows you to crisply combine lines, scatter plots and any other of the MPL Plotter
plotting methods.
#### Other arguments
As to any and all other arguments:
- **Singular arguments**: the regular MPL Plotter plotting class arguments. Apply to all curves in the plot.
- **Plural arguments**: pass a list of arguments, one for each curve. The result is as you'd imagine.
```
from mpl_plotter.two_d import comparison, line, scatter
def f(x, y, **kwargs):
    line(x, y,
         line_width=2,
         **kwargs)
def g(x, y, **kwargs):
    scatter(x, y,
            marker="D",
            point_size=10,
            **kwargs)
def h(x, y, **kwargs):
    scatter(x, y,
            marker="s",
            point_size=5,
            **kwargs)
comparison([x, x, x],
           [u, v, w],
           [f, g, h],
           plot_labels=["sin", "cos", "tan"],
           zorders=[1, 2, 3],
           colors=['C1', 'C2', 'C3'],
           alphas=[0.5, 0.5, 1],
           x_custom_tick_labels=[0, r"$\frac{\pi}{8}$", r"$\frac{\pi}{4}$"],
           show=show, backend=backend
           )
```
![alt text](demo/gallery/2d/comparison_custom.png "Curve comparison")
### 5.2 `panes`
The panes function allows for the plotting of a series of graphs in side-by-side panes. As to data input, the table below applies. 
It uses the `comparison`, function under the hood so the same input guidelines apply for all other inputs.
|   x                              |   y                               |  result  |  notes                                          |
|  ---                             |  ---                              |  ---     |  ---                                            |
|  array                           |  array                            |  11      |                                                 |
|  array                           |  [array, array]                   |  12      |  Both `y`s share `x`                            |
|  [n*[array]]                     |  [n*[array]]                      |  1n      |  Each `y` has an `x`                            |
|  array                           |  [array, array]                   |  21      |  Both `y`s share `x`                            |
|  [array, array]                  |  [array, array]                   |  21      |  Each `y` has an `x`                            |
|  array                           |  [n*[array], n*[array]]           |  2n      |  All curves in all (2) panes share a single `x` |
|  [array, array]                  |  [n*[array], n*[array]]           |  2n      |  All curves in each pane share an `x`           |
|  [n*[array], n*[array]]          |  [n*[array], n*[array]]           |  2n      |  All curves in all (2) panes have their own `x` |
|  [n*[array], ... up to m]        |  [n*[array], ... up to m]         |  mn      |  All curves in all panes have their own `x`     |
### Code
The following plots one curve per pane (3 in total):
```
panes(x,                   # Horizontal vector
      [u, v, y],           # List of curves to be plotted
      ["u", "v", "y"],     # List of vertical axis labels
      ["a", "b", "c"]      # List of legend labels 
      )
```
![alt text](demo/gallery/2d/pane_single.png "Single-curve panes")
And the following plots an arbitrary number of curves per pane. As you can see, you just need to input 
`n` **lists** of `m` curves (where `m`=2 in the example below), and you will get a plot with `n` panes, with `m`
curves in each.
```
panes(x,                               # Horizontal vector
      [[u, uu], [v, vv], [y, yy]],     # List of pairs of curves to be compared
      ["u", "v", "y"],                 # List of vertical axis labels
      ["a", "b"]                       # List of legend labels
      )
```
![alt text](demo/gallery/2d/pane_comparison.png "Multiple-curve comparison panes")
### Demo
Preposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is
available in `tests/test_panes.py`.
![alt text](demo/gallery/2d/pane_alot.png "There's a lot")
![alt text](demo/gallery/2d/pane_alot_comparison.png "Lots of triplets") 
# 6. Presets
TL;DR: Take a parameter `toml` and forget about function inputs.
### 6.1 Standard presets
Standard presets are available to remove overhead. They're tailored for my use cases but you may find them useful anyway.
| ![alt text](demo/gallery/2d/preset_publication_scatter.png "Publication preset")| ![alt text](demo/gallery/2d/preset_publication_heatmap.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_quiver.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_streamline.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_fill.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_line.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_scatter.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_surface.png "Publication preset") |
| --- | --- | --- | --- | --- | --- | --- | --- |
| ![alt text](demo/gallery/2d/preset_precision_scatter.png "Precision preset")| ![alt text](demo/gallery/2d/preset_precision_heatmap.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_quiver.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_streamline.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_fill.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_line.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_scatter.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_surface.png "Precision preset") | 
#### _Publication_
It is a common mistake to make a figure for a paper with unreadable labels. This preset tries to solve that, 
generating plots optimized to be printed on a small format, in side-by-side plots or embedded in a column of text.
    from mpl_plotter.presets.precision import two_d
    from mpl_plotter.color.schemes import one           # Custom colorscheme
    x = np.linspace(0, 4, 1000)
    y = np.exp(x)
    z = abs(np.sin(x)*np.exp(x))
    two_d.line(x, z, aspect=0.05, color=one()[-2], show=True)
![alt text](demo/gallery/2d/preset_publication_line.png "Publication preset")
#### _Precision_
Made to plot functions large on the screen, with equal x and y scales to avoid skewing the variables, and 
many ticks to visually inspect a signal.
    from mpl_plotter.presets.precision import two_d
    two_d.line(x, z, aspect=0.05, color=one()[-2], show=True)
![alt text](demo/gallery/2d/preset_precision_line.png "Precision preset")
### 6.2 Custom presets
Example workflow follows. For further reference check [the preset tests](https://github.com/alopezrivera/mpl_plotter/blob/master/tests/test_presets.py).
1. Import the preset creation function
      ```
      from mpl_plotter.presets import preset
      ```
2. Create a preset, either from a plotter,
      ```
      from mpl_plotter.two_d import line
      _preset = preset(line)
      ```
   or from a dimension. In this case, the preset will contain all common parameters to all plots
   in 2 or 3 dimensions.
      ```
      _preset = preset(dim=2)
      ```
   The preset is a dictionary. You can edit its parameters as you would expect. However, it is more convenient to
3. Save your preset in a `toml` file. This will yield you a `toml` file containing all parameters for your plot or dimension, allowing you to easily inspect defaults and tailor settings to your liking. You may edit this file as you please, as long as you do not infringe on its syntax.
      ```
      _preset.save('tests/presets/test.toml')
      ```
4. Load the file in the same -or a different session.
      ```
      from mpl_plotter.presets import preset
      _preset = preset.load('tests/presets/test.toml')
      ```
5. Import an MPL Plotter preset plotter and load it with your preset
      ```
      from mpl_plotter.presets import two_d
      _two_d = two_d(preset=_preset)
      ```
6. Plot as you wish
      ```
      _two_d.line(show=True)
      _two_d.scatter(show=True)
      _two_d.<...>
      ```
# 7. Matplotlib
### 7.1 Retrieving axes, figures
The axis and figure on which each class draws are instance attributes. To retrieve them and continue modifications 
using standard Matplotlib:
    from mpl_plotter.two_d import line
    my_plot = line()
    ax, fig = my_plot.ax, my_plot.fig
With the axis and figure, most Matplotlib functions out there can be used to further modify your plots. 
### 7.2 Using Matplotlib's axis tiling
Matplotlib allows for subplot composition using `subplot2grid`. This can be used in combination with MPL Plotter:
Importantly:
- The auxiliary function `figure` (`from mpl_plotter figure`) sets up a figure in a chosen backend. 
This is convenient, as if the figure is created with `plt.figure()`, only the default non-interactive Matplotlib 
backend will be available, unless `matplotlib.use(<backend>)` is specified before importing `pyplot`.
```
from mpl_plotter import figure
from mpl_plotter.two_d import line, quiver, streamline, fill_area
backend = "Qt5Agg"  # None -> regular non-interactive matplotlib output
figure(figsize=(10, 10), backend=backend)
ax0 = plt.subplot2grid((2, 2), (0, 0), rowspan=1)
ax1 = plt.subplot2grid((2, 2), (1, 0), rowspan=1)
ax2 = plt.subplot2grid((2, 2), (0, 1), rowspan=1)
ax3 = plt.subplot2grid((2, 2), (1, 1), rowspan=1)
axes = [ax0, ax1, ax2, ax3]
plots = [line, quiver, streamline, fill_area]
for i in range(len(plots)):
    plots[i](ax=axes[i])
plt.show()
```

%prep
%autosetup -n mpl_plotter-5.5.0

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-mpl-plotter -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Thu Jun 08 2023 Python_Bot <Python_Bot@openeuler.org> - 5.5.0-1
- Package Spec generated