-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathplugins_guide.html
More file actions
901 lines (841 loc) · 96.6 KB
/
Copy pathplugins_guide.html
File metadata and controls
901 lines (841 loc) · 96.6 KB
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
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>How to implement your own plotters and plugins — psyplot documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
<link rel="stylesheet" type="text/css" href="../_static/nc-table-styles.css?v=d585f46f" />
<link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
<link rel="stylesheet" type="text/css" href="../_static/sphinx-design.min.css?v=87e54e7c" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
<link rel="shortcut icon" href="../_static/psyplot.ico"/>
<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/design-tabs.js?v=f930bc37"></script>
<script src="../_static/js/theme.js"></script>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="Contribution and development hints" href="../contributing.html" />
<link rel="prev" title="The psyplot framework" href="framework.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../index.html" class="icon icon-home">
psyplot
<img src="../_static/psyplot.png" class="logo" alt="Logo"/>
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../about.html">About psyplot</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../about.html#why-psyplot">Why psyplot?</a></li>
<li class="toctree-l2"><a class="reference internal" href="../about.html#what-it-is-and-what-it-is-not">What it is, and what it is not</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../about.html#what-it-is">What it is</a></li>
<li class="toctree-l3"><a class="reference internal" href="../about.html#what-it-is-not">What it is not</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../about.html#about-the-author">About the author</a></li>
<li class="toctree-l2"><a class="reference internal" href="../about.html#license">License</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../installing.html">Installation</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../installing.html#how-to-install">How to install</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../installing.html#installation-using-conda">Installation using conda</a></li>
<li class="toctree-l3"><a class="reference internal" href="../installing.html#installation-using-pip">Installation using pip</a></li>
<li class="toctree-l3"><a class="reference internal" href="../installing.html#installation-from-source">Installation from source</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../installing.html#dependencies">Dependencies</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../installing.html#required-dependencies">Required dependencies</a></li>
<li class="toctree-l3"><a class="reference internal" href="../installing.html#optional-dependencies">Optional dependencies</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../installing.html#running-the-tests">Running the tests</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installing.html#building-the-docs">Building the docs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installing.html#uninstallation">Uninstallation</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../installing.html#uninstallation-via-conda">Uninstallation via conda</a></li>
<li class="toctree-l3"><a class="reference internal" href="../installing.html#uninstallation-via-pip">Uninstallation via pip</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../getting_started.html">Getting started</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../getting_started.html#initialization-and-interactive-usage">Initialization and interactive usage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../getting_started.html#choosing-the-dimension">Choosing the dimension</a></li>
<li class="toctree-l2"><a class="reference internal" href="../getting_started.html#configuring-the-appearance-of-the-plot">Configuring the appearance of the plot</a></li>
<li class="toctree-l2"><a class="reference internal" href="../getting_started.html#controlling-the-update">Controlling the update</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../getting_started.html#automatic-update">Automatic update</a></li>
<li class="toctree-l3"><a class="reference internal" href="../getting_started.html#direct-control-on-formatoption-update">Direct control on formatoption update</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../getting_started.html#creating-and-managing-multiple-plots">Creating and managing multiple plots</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../getting_started.html#creating-multiple-plots">Creating multiple plots</a></li>
<li class="toctree-l3"><a class="reference internal" href="../getting_started.html#slicing-and-filtering-the-project">Slicing and filtering the project</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../getting_started.html#saving-and-loading-your-project">Saving and loading your project</a></li>
<li class="toctree-l2"><a class="reference internal" href="../getting_started.html#using-presets">Using presets</a></li>
<li class="toctree-l2"><a class="reference internal" href="../getting_started.html#adding-your-own-script-the-post-formatoption">Adding your own script: The <code class="xref py py-attr docutils literal notranslate"><span class="pre">post</span></code> formatoption</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference external" href="https://psyplot.github.io/examples/">Example Gallery</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration.html">Configuration</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../configuration.html#the-rcparams">The <code class="docutils literal notranslate"><span class="pre">rcParams</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="../configuration.html#default-formatoptions">Default formatoptions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../projects.html">Subprojects</a></li>
<li class="toctree-l1"><a class="reference internal" href="../accessors.html">xarray Accessors</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../accessors.html#the-datasetaccessor-dataset-accessor">The <code class="xref py py-class docutils literal notranslate"><span class="pre">DatasetAccessor</span></code> dataset accessor</a></li>
<li class="toctree-l2"><a class="reference internal" href="../accessors.html#the-interactivearray-dataarray-accessor">The <code class="xref py py-class docutils literal notranslate"><span class="pre">InteractiveArray</span></code> dataarray accessor</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../accessors.html#creating-plots-with-the-dataarray-accessor">Creating plots with the dataarray accessor</a></li>
<li class="toctree-l3"><a class="reference internal" href="../accessors.html#updating-plots-and-arrays-with-the-dataarray-accessor">Updating plots and arrays with the dataarray accessor</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../plugins.html">Psyplot plugins</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../plugins.html#existing-plugins">Existing plugins</a></li>
<li class="toctree-l2"><a class="reference internal" href="../plugins.html#how-to-exclude-plugins">How to exclude plugins</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../plugins.html#the-psyplot-plugins-environment-variable">The <code class="docutils literal notranslate"><span class="pre">PSYPLOT_PLUGINS</span></code> environment variable</a></li>
<li class="toctree-l3"><a class="reference internal" href="../plugins.html#the-psyplot-plotmethods-environment-variable">The <code class="docutils literal notranslate"><span class="pre">PSYPLOT_PLOTMETHODS</span></code> environment variable</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../command_line.html">Command line usage</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../command_line.html#positional-arguments">Positional Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="../command_line.html#named-arguments">Named Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="../command_line.html#info-options">Info options</a></li>
<li class="toctree-l2"><a class="reference internal" href="../command_line.html#output-options">Output options</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Developers guide</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="framework.html">The psyplot framework</a><ul>
<li class="toctree-l3"><a class="reference internal" href="framework.html#the-project-function">The <code class="xref py py-func docutils literal notranslate"><span class="pre">project()</span></code> function</a></li>
<li class="toctree-l3"><a class="reference internal" href="framework.html#the-interactivebase-and-the-plotter-classes">The <code class="xref py py-class docutils literal notranslate"><span class="pre">InteractiveBase</span></code> and the <code class="xref py py-class docutils literal notranslate"><span class="pre">Plotter</span></code> classes</a><ul>
<li class="toctree-l4"><a class="reference internal" href="framework.html#interactive-data-objects">Interactive data objects</a></li>
<li class="toctree-l4"><a class="reference internal" href="framework.html#visualization-objects">Visualization objects</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="framework.html#formatoptions">Formatoptions</a></li>
</ul>
</li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">How to implement your own plotters and plugins</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#creating-plotters">Creating plotters</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#interface-for-the-plotter">Interface for the plotter</a></li>
<li class="toctree-l4"><a class="reference internal" href="#interface-to-the-data">Interface to the data</a></li>
<li class="toctree-l4"><a class="reference internal" href="#interfacing-to-other-formatoptions">Interfacing to other formatoptions</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#creating-new-plugins">Creating new plugins</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#creating-a-package-with-the-psyplot-plugin-template">Creating a package with the psyplot-plugin-template</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#rcparams-handling-in-plugins"><code class="docutils literal notranslate"><span class="pre">rcParams</span></code> handling in plugins</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../contributing.html">Contribution and development hints</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../contributing.html#code-of-conduct">Code of Conduct</a></li>
<li class="toctree-l2"><a class="reference internal" href="../contributing.html#what-should-i-know-before-i-get-started">What should I know before I get started?</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../contributing.html#the-psyplot-framework">The psyplot framework</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../contributing.html#contributing-in-the-development">Contributing in the development</a></li>
<li class="toctree-l2"><a class="reference internal" href="../contributing.html#helpers">Helpers</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../contributing.html#shortcuts-with-make">Shortcuts with make</a></li>
<li class="toctree-l3"><a class="reference internal" href="../contributing.html#annotating-licenses">Annotating licenses</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../contributing.html#fixing-the-docs">Fixing the docs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../contributing.html#contributing-to-the-code">Contributing to the code</a></li>
<li class="toctree-l2"><a class="reference internal" href="../contributing.html#updating-the-skeleton-for-this-package">Updating the skeleton for this package</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../api/psyplot.html">psyplot package</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../api/psyplot.html#psyplot.get_versions"><code class="docutils literal notranslate"><span class="pre">get_versions()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/psyplot.html#psyplot.with_gui"><code class="docutils literal notranslate"><span class="pre">with_gui</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="../api/psyplot.html#subpackages">Subpackages</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.config.html">psyplot.config package</a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.sphinxext.html">psyplot.sphinxext package</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../api/psyplot.html#submodules">Submodules</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html"><code class="docutils literal notranslate"><span class="pre">AbsoluteTimeDecoder</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.AbsoluteTimeEncoder"><code class="docutils literal notranslate"><span class="pre">AbsoluteTimeEncoder</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.ArrayList"><code class="docutils literal notranslate"><span class="pre">ArrayList</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.CFDecoder"><code class="docutils literal notranslate"><span class="pre">CFDecoder</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.DatasetAccessor"><code class="docutils literal notranslate"><span class="pre">DatasetAccessor</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.InteractiveArray"><code class="docutils literal notranslate"><span class="pre">InteractiveArray</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.InteractiveBase"><code class="docutils literal notranslate"><span class="pre">InteractiveBase</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.InteractiveList"><code class="docutils literal notranslate"><span class="pre">InteractiveList</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.Signal"><code class="docutils literal notranslate"><span class="pre">Signal</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.UGridDecoder"><code class="docutils literal notranslate"><span class="pre">UGridDecoder</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.decode_absolute_time"><code class="docutils literal notranslate"><span class="pre">decode_absolute_time()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.encode_absolute_time"><code class="docutils literal notranslate"><span class="pre">encode_absolute_time()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.get_filename_ds"><code class="docutils literal notranslate"><span class="pre">get_filename_ds()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.get_fname_funcs"><code class="docutils literal notranslate"><span class="pre">get_fname_funcs</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.get_index_from_coord"><code class="docutils literal notranslate"><span class="pre">get_index_from_coord()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.get_tdata"><code class="docutils literal notranslate"><span class="pre">get_tdata()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.open_dataset"><code class="docutils literal notranslate"><span class="pre">open_dataset()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.open_mfdataset"><code class="docutils literal notranslate"><span class="pre">open_mfdataset()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.setup_coords"><code class="docutils literal notranslate"><span class="pre">setup_coords()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.t_patterns"><code class="docutils literal notranslate"><span class="pre">t_patterns</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.to_netcdf"><code class="docutils literal notranslate"><span class="pre">to_netcdf()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.data.html#psyplot.data.to_slice"><code class="docutils literal notranslate"><span class="pre">to_slice()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.docstring.html"><code class="docutils literal notranslate"><span class="pre">PsyplotDocstringProcessor</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.docstring.html#psyplot.docstring.append_original_doc"><code class="docutils literal notranslate"><span class="pre">append_original_doc()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.docstring.html#psyplot.docstring.dedent"><code class="docutils literal notranslate"><span class="pre">dedent()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.docstring.html#psyplot.docstring.docstrings"><code class="docutils literal notranslate"><span class="pre">docstrings</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.docstring.html#psyplot.docstring.indent"><code class="docutils literal notranslate"><span class="pre">indent()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.gdal_store.html"><code class="docutils literal notranslate"><span class="pre">GdalStore</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html"><code class="docutils literal notranslate"><span class="pre">BEFOREPLOTTING</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.DictFormatoption"><code class="docutils literal notranslate"><span class="pre">DictFormatoption</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.END"><code class="docutils literal notranslate"><span class="pre">END</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption"><code class="docutils literal notranslate"><span class="pre">Formatoption</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.FormatoptionMeta"><code class="docutils literal notranslate"><span class="pre">FormatoptionMeta</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Plotter"><code class="docutils literal notranslate"><span class="pre">Plotter</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.PostProcDependencies"><code class="docutils literal notranslate"><span class="pre">PostProcDependencies</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.PostProcessing"><code class="docutils literal notranslate"><span class="pre">PostProcessing</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.PostTiming"><code class="docutils literal notranslate"><span class="pre">PostTiming</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.START"><code class="docutils literal notranslate"><span class="pre">START</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.default_print_func"><code class="docutils literal notranslate"><span class="pre">default_print_func()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.format_time"><code class="docutils literal notranslate"><span class="pre">format_time()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.groups"><code class="docutils literal notranslate"><span class="pre">groups</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.is_data_dependent"><code class="docutils literal notranslate"><span class="pre">is_data_dependent()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html"><code class="docutils literal notranslate"><span class="pre">DataArrayPlotter</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.DataArrayPlotterInterface"><code class="docutils literal notranslate"><span class="pre">DataArrayPlotterInterface</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.DatasetPlotter"><code class="docutils literal notranslate"><span class="pre">DatasetPlotter</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.DatasetPlotterInterface"><code class="docutils literal notranslate"><span class="pre">DatasetPlotterInterface</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.PROJECT_CLS"><code class="docutils literal notranslate"><span class="pre">PROJECT_CLS</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.PlotterInterface"><code class="docutils literal notranslate"><span class="pre">PlotterInterface</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.Project"><code class="docutils literal notranslate"><span class="pre">Project</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.ProjectPlotter"><code class="docutils literal notranslate"><span class="pre">ProjectPlotter</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.close"><code class="docutils literal notranslate"><span class="pre">close()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.gcp"><code class="docutils literal notranslate"><span class="pre">gcp()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.get_project_nums"><code class="docutils literal notranslate"><span class="pre">get_project_nums()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.multiple_subplots"><code class="docutils literal notranslate"><span class="pre">multiple_subplots()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.plot"><code class="docutils literal notranslate"><span class="pre">plot</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.project"><code class="docutils literal notranslate"><span class="pre">project()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.register_plotter"><code class="docutils literal notranslate"><span class="pre">register_plotter()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.scp"><code class="docutils literal notranslate"><span class="pre">scp()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.project.html#psyplot.project.unregister_plotter"><code class="docutils literal notranslate"><span class="pre">unregister_plotter()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html"><code class="docutils literal notranslate"><span class="pre">Defaultdict</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.check_key"><code class="docutils literal notranslate"><span class="pre">check_key()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.get_default_value"><code class="docutils literal notranslate"><span class="pre">get_default_value()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.hashable"><code class="docutils literal notranslate"><span class="pre">hashable()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.is_iterable"><code class="docutils literal notranslate"><span class="pre">is_iterable()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.is_remote_url"><code class="docutils literal notranslate"><span class="pre">is_remote_url()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.isstring"><code class="docutils literal notranslate"><span class="pre">isstring()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.join_dicts"><code class="docutils literal notranslate"><span class="pre">join_dicts()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.plugin_entrypoints"><code class="docutils literal notranslate"><span class="pre">plugin_entrypoints()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.sort_kwargs"><code class="docutils literal notranslate"><span class="pre">sort_kwargs()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.utils.html#psyplot.utils.unique_everseen"><code class="docutils literal notranslate"><span class="pre">unique_everseen()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.warning.html"><code class="docutils literal notranslate"><span class="pre">PsyPlotCritical</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.warning.html#psyplot.warning.PsyPlotRuntimeWarning"><code class="docutils literal notranslate"><span class="pre">PsyPlotRuntimeWarning</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.warning.html#psyplot.warning.PsyPlotWarning"><code class="docutils literal notranslate"><span class="pre">PsyPlotWarning</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.warning.html#psyplot.warning.critical"><code class="docutils literal notranslate"><span class="pre">critical()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.warning.html#psyplot.warning.customwarn"><code class="docutils literal notranslate"><span class="pre">customwarn()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.warning.html#psyplot.warning.disable_warnings"><code class="docutils literal notranslate"><span class="pre">disable_warnings()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="../api/psyplot.warning.html#psyplot.warning.warn"><code class="docutils literal notranslate"><span class="pre">warn()</span></code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../todos.html">ToDos</a></li>
<li class="toctree-l1"><a class="reference internal" href="../changelog.html">Changelog</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-5-1">v1.5.1</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#added">Added</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-5-0">v1.5.0</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#changed">Changed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id2">Added</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-4-3">v1.4.3</a></li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-4-2">v1.4.2</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id3">Changed</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-4-1">v1.4.1</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id4">Added</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#fixed">Fixed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id5">Changed</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-4-0">v1.4.0</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id6">Fixed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id7">Added</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id8">Changed</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-3-2">v1.3.2</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id9">Fixed</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-3-1">v1.3.1</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id10">Fixed</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-3-0">v1.3.0</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id11">Added</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id12">Changed</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-2-1">v1.2.1</a></li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-2-0">v1.2.0</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id13">Added</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#removed">Removed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id14">Changed</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-1-0">v1.1.0</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id15">Added</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../changelog.html#v1-0-0">v1.0.0</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id16">Added</a></li>
<li class="toctree-l3"><a class="reference internal" href="../changelog.html#id17">Changed</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">psyplot</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="index.html">Developers guide</a></li>
<li class="breadcrumb-item active">How to implement your own plotters and plugins</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/develop/plugins_guide.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="how-to-implement-your-own-plotters-and-plugins">
<span id="plugins-guide"></span><h1>How to implement your own plotters and plugins<a class="headerlink" href="#how-to-implement-your-own-plotters-and-plugins" title="Link to this heading"></a></h1>
<p>New plotters and plugins to the psyplot framework are highly welcomed. In this
guide, we present <a class="reference internal" href="#new-plotters"><span class="std std-ref">how to create new plotters</span></a> and explain
to you how you can <a class="reference internal" href="#new-plugins"><span class="std std-ref">include them as a plugin in psyplot</span></a>.</p>
<section id="creating-plotters">
<span id="new-plotters"></span><h2>Creating plotters<a class="headerlink" href="#creating-plotters" title="Link to this heading"></a></h2>
<p>Implementing new plotters can be very easy or quite an effort depending on how
sophisticated you want to do it. In principle, you only have to implement the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.update" title="psyplot.plotter.Formatoption.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Formatoption.update()</span></code></a> method and a default value. I.e., one simple
formatoption would be</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [1]: </span><span class="kn">from</span> <span class="nn">psyplot.plotter</span> <span class="kn">import</span> <span class="n">Formatoption</span><span class="p">,</span> <span class="n">Plotter</span>
<span class="gp">In [2]: </span><span class="k">class</span> <span class="nc">MyFormatoption</span><span class="p">(</span><span class="n">Formatoption</span><span class="p">):</span>
<span class="gp"> ...: </span> <span class="n">default</span> <span class="o">=</span> <span class="s1">'my text'</span>
<span class="gp"> ...: </span> <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="gp"> ...: </span> <span class="bp">self</span><span class="o">.</span><span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="s1">'xx-large'</span><span class="p">)</span>
<span class="gp"> ...: </span>
</pre></div>
</div>
<p>together with a plotter</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [3]: </span><span class="k">class</span> <span class="nc">MyPlotter</span><span class="p">(</span><span class="n">Plotter</span><span class="p">):</span>
<span class="gp"> ...: </span> <span class="n">my_fmt</span> <span class="o">=</span> <span class="n">MyFormatoption</span><span class="p">(</span><span class="s1">'my_fmt'</span><span class="p">)</span>
<span class="gp"> ...: </span>
</pre></div>
</div>
<p>and your done. Now you can make a simple plot</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [4]: </span><span class="kn">from</span> <span class="nn">psyplot</span> <span class="kn">import</span> <span class="n">open_dataset</span>
<span class="gp">In [5]: </span><span class="n">ds</span> <span class="o">=</span> <span class="n">open_dataset</span><span class="p">(</span><span class="s1">'demo.nc'</span><span class="p">)</span>
<span class="gp">In [6]: </span><span class="n">plotter</span> <span class="o">=</span> <span class="n">MyPlotter</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">t2m</span><span class="p">)</span>
</pre></div>
</div>
<a class="reference internal image-reference" href="../_images/docs_demo_MyPlotter_simple.png"><img alt="../_images/docs_demo_MyPlotter_simple.png" src="../_images/docs_demo_MyPlotter_simple.png" style="width: 4in;" /></a>
<p>However, if you’re using the psyplot framework, you probably will be a bit more
advanced so let’s talk about attributes and methods of the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption" title="psyplot.plotter.Formatoption"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatoption</span></code></a>
class.</p>
<p>If you look into the documentation of the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption" title="psyplot.plotter.Formatoption"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatoption</span></code></a> class, you find
quite a lot of attributes and methods which probably is a bit depressing and
confusing. But in principle, we can group them into 4 categories, the interface
to the data, to the plotter and to other formatoptions. Plus an additional
category for some Formatoption internals you definitely have to care about.</p>
<section id="interface-for-the-plotter">
<h3>Interface for the plotter<a class="headerlink" href="#interface-for-the-plotter" title="Link to this heading"></a></h3>
<p>The first interface is the one, that interfaces to the plotter. The most
important attributes in this group are the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.key" title="psyplot.plotter.Formatoption.key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">key</span></code></a>,
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.priority" title="psyplot.plotter.Formatoption.priority"><code class="xref py py-attr docutils literal notranslate"><span class="pre">priority</span></code></a>, <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.plot_fmt" title="psyplot.plotter.Formatoption.plot_fmt"><code class="xref py py-attr docutils literal notranslate"><span class="pre">plot_fmt</span></code></a>,
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.initialize_plot" title="psyplot.plotter.Formatoption.initialize_plot"><code class="xref py py-meth docutils literal notranslate"><span class="pre">initialize_plot()</span></code></a> and most important the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.update" title="psyplot.plotter.Formatoption.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> method.</p>
<p>The <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.key" title="psyplot.plotter.Formatoption.key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">key</span></code></a> is the unique key for the formatoption inside the
plotter. In our example above, we assign the <code class="docutils literal notranslate"><span class="pre">'my_fmt'</span></code> key to the
<code class="docutils literal notranslate"><span class="pre">MyFormatoption</span></code> class in <code class="docutils literal notranslate"><span class="pre">MyPlotter</span></code>. Hence, this key is defined when the
plotter class is defined and will be automatically assigned to the formatoption.</p>
<p>The next important attribute is the <code class="xref py py-attr docutils literal notranslate"><span class="pre">priority</span></code> attribute. There are three
stages in the update of a plotter:</p>
<ol class="arabic simple">
<li><p>The stage with data manipulation. If formatoptions manipulate the data that
shall be visualized (the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.data" title="psyplot.plotter.Formatoption.data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">data</span></code></a> attribute), those
formatoptions are updated first. They have the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.START" title="psyplot.plotter.START"><code class="xref py py-attr docutils literal notranslate"><span class="pre">psyplot.plotter.START</span></code></a>
priority</p></li>
<li><p>The stage of the plot. Formatoptions that influence how the data is
visualized are updated here (e.g. the colormap or formatoptions that do the
plotting). They have the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.BEFOREPLOTTING" title="psyplot.plotter.BEFOREPLOTTING"><code class="xref py py-attr docutils literal notranslate"><span class="pre">psyplot.plotter.BEFOREPLOTTING</span></code></a> priority.</p></li>
<li><p>The stage of the plot where additional informations are inserted. Here all
the labels are updated, e.g. the title, xlabel, etc.. This is the default
priority of the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.priority" title="psyplot.plotter.Formatoption.priority"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatoption.priority</span></code></a> attribute, the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.END" title="psyplot.plotter.END"><code class="xref py py-attr docutils literal notranslate"><span class="pre">psyplot.plotter.END</span></code></a> priority.</p></li>
</ol>
<p>If there is any formatoption updated within the first two groups, the plot of
the plotter is updated. This brings us to the third important attribute, the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.plot_fmt" title="psyplot.plotter.Formatoption.plot_fmt"><code class="xref py py-attr docutils literal notranslate"><span class="pre">plot_fmt</span></code></a>. This boolean tells the plotter, whether the
corresponding formatoption is assumed to make a plot at the end of the second
stage (the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.BEFOREPLOTTING" title="psyplot.plotter.BEFOREPLOTTING"><code class="xref py py-attr docutils literal notranslate"><span class="pre">BEFOREPLOTTING</span></code></a> stage). If this attribute is
<code class="docutils literal notranslate"><span class="pre">True</span></code>, then the plotter will call the <code class="xref py py-meth docutils literal notranslate"><span class="pre">Formatoption.make_plot()</span></code> method
of the formatoption instance.</p>
<p>Finally, the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.initialize_plot" title="psyplot.plotter.Formatoption.initialize_plot"><code class="xref py py-meth docutils literal notranslate"><span class="pre">initialize_plot()</span></code></a> and
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.update" title="psyplot.plotter.Formatoption.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> methods, this is were your contribution really is
required. The <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.initialize_plot" title="psyplot.plotter.Formatoption.initialize_plot"><code class="xref py py-meth docutils literal notranslate"><span class="pre">initialize_plot()</span></code></a> method is called when the
plot is created for the first time, the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.update" title="psyplot.plotter.Formatoption.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> method
when it is updated (the default implementation of the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.initialize_plot" title="psyplot.plotter.Formatoption.initialize_plot"><code class="xref py py-meth docutils literal notranslate"><span class="pre">initialize_plot()</span></code></a> simply calls the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.update" title="psyplot.plotter.Formatoption.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> method). Implement these methods in your
formatoption and thereby make use of the interface to the
<a class="reference internal" href="#fmt-data-interface"><span class="std std-ref">data</span></a> and other
<a class="reference internal" href="#fmt-fmt-interface"><span class="std std-ref">formatoptions</span></a>.</p>
</section>
<section id="interface-to-the-data">
<span id="fmt-data-interface"></span><h3>Interface to the data<a class="headerlink" href="#interface-to-the-data" title="Link to this heading"></a></h3>
<p>The next set of attributes help you to interface to the data. There are two
important parts in this section the interface to the data and the
interpretation of the data.</p>
<p>The first part is mainly represented to the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.data" title="psyplot.plotter.Formatoption.data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Formatoption.data</span></code></a> and
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.raw_data" title="psyplot.plotter.Formatoption.raw_data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Formatoption.raw_data</span></code></a> attributes. The plotter that contains the
formatoption often creates a copy of the data because the data for
the visualization might be modified (see for example the
<code class="xref py py-class docutils literal notranslate"><span class="pre">psy_reg.plotter.LinRegPlotter</span></code>). This modified data can be accessed
through the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.data" title="psyplot.plotter.Formatoption.data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Formatoption.data</span></code></a> and should be the standard approach to
access the data within a formatoption. Nevertheless, the original data can be
accessed through the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.raw_data" title="psyplot.plotter.Formatoption.raw_data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Formatoption.raw_data</span></code></a> attribute. However, it only
makes sense to access this data for formatoption with <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.START" title="psyplot.plotter.START"><code class="xref py py-attr docutils literal notranslate"><span class="pre">START</span></code></a>
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.priority" title="psyplot.plotter.Formatoption.priority"><code class="xref py py-attr docutils literal notranslate"><span class="pre">priority</span></code></a>.</p>
<p>The result of these two attributes depend on the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.index_in_list" title="psyplot.plotter.Formatoption.index_in_list"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Formatoption.index_in_list</span></code></a> attribute. The data objects in the psyplot
framework are either a <a class="reference external" href="https://docs.xarray.dev/en/stable/generated/xarray.DataArray.html#xarray.DataArray" title="(in xarray v2024.6.1.dev0)"><code class="xref py py-class docutils literal notranslate"><span class="pre">xarray.DataArray</span></code></a> or a list of those in a
<a class="reference internal" href="../api/psyplot.data.html#psyplot.data.InteractiveList" title="psyplot.data.InteractiveList"><code class="xref py py-class docutils literal notranslate"><span class="pre">psyplot.data.InteractiveList</span></code></a>. If the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.index_in_list" title="psyplot.plotter.Formatoption.index_in_list"><code class="xref py py-attr docutils literal notranslate"><span class="pre">index_in_list</span></code></a> attribute is not None, and the data object
is an <a class="reference internal" href="../api/psyplot.data.html#psyplot.data.InteractiveList" title="psyplot.data.InteractiveList"><code class="xref py py-class docutils literal notranslate"><span class="pre">InteractiveList</span></code></a>, then only the array at the
specified position is returned. To completely avoid this issue, you might also
use the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.iter_data" title="psyplot.plotter.Formatoption.iter_data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">iter_data</span></code></a> or <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.iter_raw_data" title="psyplot.plotter.Formatoption.iter_raw_data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">iter_raw_data</span></code></a>
attributes.</p>
<p>The second part in this section is the interpretation of the data and here,
the formatoption can use the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.decoder" title="psyplot.plotter.Formatoption.decoder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Formatoption.decoder</span></code></a> attribute. This
subclass of the <a class="reference internal" href="../api/psyplot.data.html#psyplot.data.CFDecoder" title="psyplot.data.CFDecoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">psyplot.data.CFDecoder</span></code></a> helps you to identify the
x- and y-variables in the data.</p>
</section>
<section id="interfacing-to-other-formatoptions">
<span id="fmt-fmt-interface"></span><h3>Interfacing to other formatoptions<a class="headerlink" href="#interfacing-to-other-formatoptions" title="Link to this heading"></a></h3>
<p>A formatoption is the lowest level in the psyplot framework. It is represented
at multiple levels:</p>
<ol class="arabic simple">
<li><p>at the lowest level through the subclass of the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption" title="psyplot.plotter.Formatoption"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatoption</span></code></a> class</p></li>
<li><p>at the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Plotter" title="psyplot.plotter.Plotter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Plotter</span></code></a> class level which includes the formatoption class
as a descriptor (in our example above it’s <code class="docutils literal notranslate"><span class="pre">MyPlotter.my_fmt</span></code>)</p></li>
<li><p>at the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Plotter" title="psyplot.plotter.Plotter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Plotter</span></code></a> instance level through</p>
<ol class="lowerroman simple">
<li><p>a personalized instance of the corresponding <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption" title="psyplot.plotter.Formatoption"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatoption</span></code></a> class
(i.e. <code class="docutils literal notranslate"><span class="pre">plotter</span> <span class="pre">=</span> <span class="pre">MyPlotter();</span> <span class="pre">plotter.my_fmt</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">MyPlotter.my_fmt</span></code>)</p></li>
<li><p>an item in the plotter (i.e. <code class="docutils literal notranslate"><span class="pre">plotter</span> <span class="pre">=</span> <span class="pre">MyPlotter();</span> <span class="pre">plotter['my_fmt']</span></code>)</p></li>
</ol>
</li>
<li><p>In the update methods of the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Plotter" title="psyplot.plotter.Plotter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Plotter</span></code></a>,
<a class="reference internal" href="../api/psyplot.data.html#psyplot.data.InteractiveBase" title="psyplot.data.InteractiveBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">psyplot.data.InteractiveBase</span></code></a> and <a class="reference internal" href="../api/psyplot.data.html#psyplot.data.ArrayList" title="psyplot.data.ArrayList"><code class="xref py py-class docutils literal notranslate"><span class="pre">psyplot.data.ArrayList</span></code></a>
as a keyword (i.e.
<code class="docutils literal notranslate"><span class="pre">plotter</span> <span class="pre">=</span> <span class="pre">MyPlotter();</span> <span class="pre">plotter.update(my_fmt='new</span> <span class="pre">value')</span></code>)</p></li>
</ol>
<p>Hence, there is one big to the entire framework, that is: the functionality
of a new formatoption has to be completely defined through exactly one argument,
i.e. it must be possible to assign a value to the formatoption in the plotter.</p>
<p>For complex formatoption, this might indeed be quite a challenge for the
developer and there are two solutions to it:</p>
<ol class="arabic simple">
<li><p>The simple solution for the developer: Allow a dictionary as a formatoption,
here we also have the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.DictFormatoption" title="psyplot.plotter.DictFormatoption"><code class="xref py py-class docutils literal notranslate"><span class="pre">psyplot.plotter.DictFormatoption</span></code></a> to help you.</p></li>
<li><p>Interface to other formatoptions</p></li>
</ol>
<section id="first-solution-use-a-dict">
<h4>First solution: Use a <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.12)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a><a class="headerlink" href="#first-solution-use-a-dict" title="Link to this heading"></a></h4>
<p>That said, to implement a formatoption that inserts a custom text and let the
user define the size of the text, you either create a formatoption that accepts
a text via</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CustomText</span><span class="p">(</span><span class="n">DictFormatoption</span><span class="p">):</span>
<span class="n">default</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'text'</span><span class="p">:</span> <span class="s1">''</span><span class="p">}</span>
<span class="n">text</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">def</span> <span class="nf">validate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
<span class="k">return</span> <span class="p">{</span><span class="s1">'text'</span><span class="p">:</span> <span class="n">value</span><span class="p">}</span>
<span class="k">return</span> <span class="n">value</span>
<span class="k">def</span> <span class="nf">initialize_plot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="n">value</span><span class="p">[</span><span class="s1">'text'</span><span class="p">],</span>
<span class="n">fontsize</span><span class="o">=</span><span class="n">value</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'size'</span><span class="p">,</span> <span class="s1">'large'</span><span class="p">))</span>
<span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">set_text</span><span class="p">(</span><span class="n">value</span><span class="p">[</span><span class="s1">'text'</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">set_fontsize</span><span class="p">(</span><span class="n">value</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'size'</span><span class="p">,</span> <span class="s1">'large'</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">MyPlotter</span><span class="p">(</span><span class="n">Plotter</span><span class="p">):</span>
<span class="n">my_fmt</span> <span class="o">=</span> <span class="n">CustomText</span><span class="p">(</span><span class="s1">'my_fmt'</span><span class="p">)</span>
</pre></div>
</div>
<p>and then you could create and update a plotter via</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">p</span> <span class="o">=</span> <span class="n">MyPlotter</span><span class="p">(</span><span class="n">xarray</span><span class="o">.</span><span class="n">DataArray</span><span class="p">([]))</span>
<span class="n">p</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">my_fmt</span><span class="o">=</span><span class="s1">'my text'</span><span class="p">)</span> <span class="c1"># updates the text</span>
<span class="n">p</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">my_fmt</span><span class="o">=</span><span class="p">{</span><span class="s1">'size'</span><span class="p">:</span> <span class="mi">14</span><span class="p">})</span> <span class="c1"># updates the size</span>
<span class="n">p</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">my_fmt</span><span class="o">=</span><span class="p">{</span><span class="s1">'size'</span><span class="p">:</span> <span class="mi">14</span><span class="p">,</span> <span class="s1">'text'</span><span class="p">:</span> <span class="s1">'Something'</span><span class="p">})</span> <span class="c1"># updates text and size</span>
</pre></div>
</div>
<p>This solution has the several advantages:</p>
<ul class="simple">
<li><p>The user does not get confused through too many formatoptions</p></li>
<li><p>It is easy to allow more keywords for this formatoption</p></li>
</ul>
<p>Indeed, the <code class="xref py py-class docutils literal notranslate"><span class="pre">psy_simple.plotter.Legend</span></code> formatoption uses this framework
since the <a class="reference external" href="https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html#matplotlib.pyplot.legend" title="(in Matplotlib v3.9.1)"><code class="xref py py-func docutils literal notranslate"><span class="pre">matplotlib.pyplot.legend()</span></code></a> function accepts that many keywords
that it would be not informative to create a formatoption for each of them.</p>
<p>Otherwise you could of course avoid the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.DictFormatoption" title="psyplot.plotter.DictFormatoption"><code class="xref py py-class docutils literal notranslate"><span class="pre">DictFormatoption</span></code></a> and just
force the user to always provide a new dictionary.</p>
</section>
<section id="second-solution-interact-with-other-formatoptions">
<h4>Second solution: Interact with other formatoptions<a class="headerlink" href="#second-solution-interact-with-other-formatoptions" title="Link to this heading"></a></h4>
<p>Another possibility is to implement a second formatoption for the size of the
text. And here, the psyplot framework helps you with several attributes of the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption" title="psyplot.plotter.Formatoption"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatoption</span></code></a> class:</p>
<dl class="simple">
<dt>the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.children" title="psyplot.plotter.Formatoption.children"><code class="xref py py-attr docutils literal notranslate"><span class="pre">children</span></code></a> attribute</dt><dd><p>Forces the listed formatoptions in this list to be updated before the
current formatoption is updated</p>
</dd>
<dt>the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.dependencies" title="psyplot.plotter.Formatoption.dependencies"><code class="xref py py-attr docutils literal notranslate"><span class="pre">dependencies</span></code></a> attributes</dt><dd><p>Same as <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.children" title="psyplot.plotter.Formatoption.children"><code class="xref py py-attr docutils literal notranslate"><span class="pre">children</span></code></a> but also forces an update if one
of the named formatoptions are updated</p>
</dd>
<dt>the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.parents" title="psyplot.plotter.Formatoption.parents"><code class="xref py py-attr docutils literal notranslate"><span class="pre">parents</span></code></a> attribute</dt><dd><p>Skip the update if one of the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.parents" title="psyplot.plotter.Formatoption.parents"><code class="xref py py-attr docutils literal notranslate"><span class="pre">parents</span></code></a> is updated</p>
</dd>
<dt>the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.connections" title="psyplot.plotter.Formatoption.connections"><code class="xref py py-attr docutils literal notranslate"><span class="pre">connections</span></code></a> attribute</dt><dd><p>just provides connections to the listed formatoptions</p>
</dd>
</dl>
<p>Each of those attributes accept a list of strings that represent the
formatoption keys of other formatoptions. Those formatoptions are then
accessible within the formatoption via the usual <a class="reference external" href="https://docs.python.org/3/library/functions.html#getattr" title="(in Python v3.12)"><code class="xref py py-func docutils literal notranslate"><span class="pre">getattr()</span></code></a>. I.e. if you
list a formatoption in the <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.children" title="psyplot.plotter.Formatoption.children"><code class="xref py py-attr docutils literal notranslate"><span class="pre">children</span></code></a> attribute, you can
access it inside the formatoption (<code class="docutils literal notranslate"><span class="pre">self</span></code>) via <code class="docutils literal notranslate"><span class="pre">self.other_formatoption</span></code>.</p>
<p>In our example of the <code class="docutils literal notranslate"><span class="pre">CustomText</span></code>, this could be implemented via</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CustomTextSize</span><span class="p">(</span><span class="n">Formatoption</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> Set the fontsize of the custom text</span>
<span class="sd"> Possible types</span>
<span class="sd"> --------------</span>
<span class="sd"> int</span>
<span class="sd"> The fontsize of the text</span>
<span class="sd"> """</span>
<span class="n">default</span> <span class="o">=</span> <span class="nb">int</span>
<span class="k">def</span> <span class="nf">validate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="c1"># this text has not to be updated if the custom text is updated</span>
<span class="n">children</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'text'</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">set_fontsize</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">CustomText</span><span class="p">(</span><span class="n">Formatoption</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> Place a text</span>
<span class="sd"> Possible types</span>
<span class="sd"> --------------</span>
<span class="sd"> str</span>
<span class="sd"> The text to display"""</span><span class="s2">"</span>
<span class="k">def</span> <span class="nf">initialize_plot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="n">value</span><span class="p">[</span><span class="s1">'text'</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">set_text</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">MyPlotter</span><span class="p">(</span><span class="n">Plotter</span><span class="p">):</span>
<span class="n">my_fmt</span> <span class="o">=</span> <span class="n">CustomText</span><span class="p">(</span><span class="s1">'my_fmt'</span><span class="p">)</span>
<span class="n">my_fmtsize</span> <span class="o">=</span> <span class="n">CustomTextSize</span><span class="p">(</span><span class="s1">'my_fmtsize'</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s1">'my_fmt'</span><span class="p">)</span>
</pre></div>
</div>
<p>the update in that sense would be like</p>
<p>and then you could create and update a plotter via</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">p</span> <span class="o">=</span> <span class="n">MyPlotter</span><span class="p">(</span><span class="n">xarray</span><span class="o">.</span><span class="n">DataArray</span><span class="p">([]))</span>
<span class="n">p</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">my_fmt</span><span class="o">=</span><span class="s1">'my text'</span><span class="p">)</span> <span class="c1"># updates the text</span>
<span class="n">p</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">my_fmtsize</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span> <span class="c1"># updates the size</span>
<span class="n">p</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">my_fmt</span><span class="o">=</span><span class="s1">'Something'</span><span class="p">,</span> <span class="n">my_fmtsize</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span> <span class="c1"># updates text and size</span>
</pre></div>
</div>
<p>The advantages of this methodology are basically:</p>
<ul>
<li><p>The user straight away sees two formatoptions that can be interpreted
easiliy</p></li>
<li><p>The formatoption that controls the font size could easily be subclassed and
replaced in a subclass of <code class="docutils literal notranslate"><span class="pre">MyPlotter</span></code>. In the first framework using the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.DictFormatoption" title="psyplot.plotter.DictFormatoption"><code class="xref py py-class docutils literal notranslate"><span class="pre">DictFormatoption</span></code></a>, this would mean that the entire process has to be
rewritten.</p>
<p>As you see in the above definition
<code class="docutils literal notranslate"><span class="pre">my_fmtsize</span> <span class="pre">=</span> <span class="pre">CustomTextSize('my_fmtsize',</span> <span class="pre">text='my_fmt')</span></code>, we provide an
additional <code class="docutils literal notranslate"><span class="pre">text</span></code> keyword. That is because we explicitly named the
<code class="docutils literal notranslate"><span class="pre">text</span></code> key in the <code class="docutils literal notranslate"><span class="pre">children</span></code> attribute of the <code class="docutils literal notranslate"><span class="pre">CustomTextSize</span></code>
formatoption. In that way we can tell the <code class="docutils literal notranslate"><span class="pre">my_fmtsize</span></code> formatoption how to
find the necessary formatoption. That works for all keys listed in the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.children" title="psyplot.plotter.Formatoption.children"><code class="xref py py-attr docutils literal notranslate"><span class="pre">children</span></code></a>, <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.dependencies" title="psyplot.plotter.Formatoption.dependencies"><code class="xref py py-attr docutils literal notranslate"><span class="pre">dependencies</span></code></a>,
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.parents" title="psyplot.plotter.Formatoption.parents"><code class="xref py py-attr docutils literal notranslate"><span class="pre">parents</span></code></a> and <a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.connections" title="psyplot.plotter.Formatoption.connections"><code class="xref py py-attr docutils literal notranslate"><span class="pre">connections</span></code></a>
attributes.</p>
</li>
</ul>
</section>
</section>
</section>
<section id="creating-new-plugins">
<span id="new-plugins"></span><h2>Creating new plugins<a class="headerlink" href="#creating-new-plugins" title="Link to this heading"></a></h2>
<p>Now that you have created your plotter, you may want to include it in the
plot methods of the <a class="reference internal" href="../api/psyplot.project.html#psyplot.project.Project" title="psyplot.project.Project"><code class="xref py py-class docutils literal notranslate"><span class="pre">Project</span></code></a> class such that you can
do something like</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">psyplot.project</span> <span class="k">as</span> <span class="nn">psy</span>
<span class="n">psy</span><span class="o">.</span><span class="n">plot</span><span class="o">.</span><span class="n">my_plotter</span><span class="p">(</span><span class="s1">'netcdf-file.nc'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'varname'</span><span class="p">)</span>
</pre></div>
</div>
<p>There are three possibilities how you can do this:</p>
<ol class="arabic simple">
<li><p>The easy and fast solution for one session: register the plotter using the
<a class="reference internal" href="../api/psyplot.project.html#psyplot.project.register_plotter" title="psyplot.project.register_plotter"><code class="xref py py-func docutils literal notranslate"><span class="pre">psyplot.project.register_plotter()</span></code></a> function</p></li>
<li><p>The easy and steady solution: Save the calls you used in step 1 in the
<code class="docutils literal notranslate"><span class="pre">'project.plotter.user'</span></code> key of the
<a class="reference internal" href="../api/psyplot.config.rcsetup.html#psyplot.config.rcsetup.rcParams" title="psyplot.config.rcsetup.rcParams"><code class="xref py py-attr docutils literal notranslate"><span class="pre">rcParams</span></code></a></p></li>
<li><p>The steady and shareable solution: Create a new plugin</p></li>
</ol>
<p>The third solution has been used for the <a class="reference external" href="https://psyplot.github.io/psy-maps/">psy-maps</a> and <a class="reference external" href="https://psyplot.github.io/psy-simple/">psy-simple</a> plugins and
will be described in the following section.</p>
<section id="creating-a-package-with-the-psyplot-plugin-template">
<h3>Creating a package with the psyplot-plugin-template<a class="headerlink" href="#creating-a-package-with-the-psyplot-plugin-template" title="Link to this heading"></a></h3>
<p>The <a class="reference external" href="https://codebase.helmholtz.cloud/psyplot/psyplot-plugin-template">psyplot-plugin-template</a> provides a template to create a python package that
integrates with the psyplot environment. We recommend using this template as it
already contains a setup for automated formatters and linters, and a setup for
continuous integration.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>When creating a real package, we strongly recommend to use <a class="reference external" href="https://cruft.github.io/cruft">cruft</a> instead
of <a class="reference external" href="https://cookiecutter.readthedocs.io">cookiecutter</a>!</p>
</div>
<p>For our demonstration, let’s create a plugin named <em>my-plugin</em>. We will save
this name in to a YAML-file and use this to create our new plugin.</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [7]: </span><span class="o">!</span><span class="nb">echo</span><span class="w"> </span><span class="s2">"default_context: {project_slug: my-plugin}"</span><span class="w"> </span>><span class="w"> </span><span class="s2">"config.yaml"</span>
<span class="gp">In [8]: </span><span class="n">cookiecutter</span> <span class="o">--</span><span class="n">no</span><span class="o">-</span><span class="nb">input</span> <span class="o">--</span><span class="n">config</span><span class="o">-</span><span class="n">file</span> <span class="n">config</span><span class="o">.</span><span class="n">yaml</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">codebase</span><span class="o">.</span><span class="n">helmholtz</span><span class="o">.</span><span class="n">cloud</span><span class="o">/</span><span class="n">psyplot</span><span class="o">/</span><span class="n">psyplot</span><span class="o">-</span><span class="n">plugin</span><span class="o">-</span><span class="n">template</span><span class="o">.</span><span class="n">git</span>
<span class="gp">In [9]: </span><span class="kn">import</span> <span class="nn">glob</span>
<span class="gp">In [10]: </span><span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s1">'my-plugin/**'</span><span class="p">,</span> <span class="n">recursive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gh">Out[10]: </span>
<span class="go">['my-plugin/',</span>
<span class="go"> 'my-plugin/my_plugin',</span>
<span class="go"> 'my-plugin/my_plugin/py.typed',</span>
<span class="go"> 'my-plugin/my_plugin/_version.py',</span>
<span class="go"> 'my-plugin/my_plugin/plugin.py',</span>
<span class="go"> 'my-plugin/my_plugin/__init__.py',</span>
<span class="go"> 'my-plugin/my_plugin/plotters.py',</span>
<span class="go"> 'my-plugin/tests',</span>
<span class="go"> 'my-plugin/tests/test_imports.py',</span>
<span class="go"> 'my-plugin/setup.py',</span>
<span class="go"> 'my-plugin/pyproject.toml',</span>
<span class="go"> 'my-plugin/conftest.py',</span>
<span class="go"> 'my-plugin/docs',</span>
<span class="go"> 'my-plugin/docs/installation.md',</span>
<span class="go"> 'my-plugin/docs/index.md',</span>
<span class="go"> 'my-plugin/docs/requirements.txt',</span>
<span class="go"> 'my-plugin/docs/_templates',</span>
<span class="go"> 'my-plugin/docs/_templates/footer.html',</span>
<span class="go"> 'my-plugin/docs/make.bat',</span>
<span class="go"> 'my-plugin/docs/contributing.md',</span>
<span class="go"> 'my-plugin/docs/_static',</span>
<span class="go"> 'my-plugin/docs/_static/license_logo.png.license',</span>
<span class="go"> 'my-plugin/docs/_static/license_logo.png',</span>
<span class="go"> 'my-plugin/docs/api.md',</span>
<span class="go"> 'my-plugin/docs/conf.py',</span>
<span class="go"> 'my-plugin/docs/Makefile',</span>
<span class="go"> 'my-plugin/README.md',</span>
<span class="go"> 'my-plugin/CITATION.cff',</span>
<span class="go"> 'my-plugin/CHANGELOG.md',</span>
<span class="go"> 'my-plugin/MANIFEST.in',</span>
<span class="go"> 'my-plugin/tox.ini',</span>
<span class="go"> 'my-plugin/Makefile']</span>
</pre></div>
</div>
<p>The following files are created in a directory named <code class="docutils literal notranslate"><span class="pre">'my-plugin'</span></code>:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">pyproject.toml</span></code></dt><dd><p>The python package configuration</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">'my_python_package/plugin.py'</span></code></dt><dd><p>The file that sets up the configuration of our plugin. This file should
define the <code class="docutils literal notranslate"><span class="pre">rcParams</span></code> for the plugin (see also <a class="reference internal" href="#plugins-rcparams"><span class="std std-ref">rcParams handling in plugins</span></a>)</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">'my_python_package/plotters.py'</span></code></dt><dd><p>The file in which we define the plotters. This file should contain the
plotters and formatoptions from our previous section.</p>
</dd>
</dl>
<p>If you want to see more, look into the comments in the created files.</p>
</section>
</section>
<section id="rcparams-handling-in-plugins">
<span id="plugins-rcparams"></span><h2><code class="docutils literal notranslate"><span class="pre">rcParams</span></code> handling in plugins<a class="headerlink" href="#rcparams-handling-in-plugins" title="Link to this heading"></a></h2>
<p>Every formatoption does have default values. In
<a class="reference internal" href="#new-plotters"><span class="std std-ref">our example above</span></a>, we simply set it via the
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.default" title="psyplot.plotter.Formatoption.default"><code class="xref py py-attr docutils literal notranslate"><span class="pre">default</span></code></a> attribute. This is a hard-coded,
but easy, stable and quick solution.</p>
<p>However, your formatoption could also be used in different plotters, each
requiring a different default value. Or you want to give the user the
possibility to set his own default value. For this, we implemented the</p>
<table class="autosummary longtable docutils align-default">
<tbody>
<tr class="row-odd"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">psyplot.plotter.Plotter._rcparams_string</span></code></p></td>
<td><p>List of base strings in the <code class="xref py py-attr docutils literal notranslate"><span class="pre">psyplot.rcParams</span></code> dictionary</p></td>
</tr>
</tbody>
</table>
<p>attribute. Here you can specify a string for this plotter which is used to
get the default value of the formatoptions in this plotter from the
<a class="reference internal" href="../api/psyplot.config.rcsetup.html#psyplot.config.rcsetup.rcParams" title="psyplot.config.rcsetup.rcParams"><code class="xref py py-attr docutils literal notranslate"><span class="pre">rcParams</span></code></a>. The expected
<a class="reference internal" href="../api/psyplot.plotter.html#psyplot.plotter.Formatoption.default_key" title="psyplot.plotter.Formatoption.default_key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">default_key</span></code></a> for one formatoption would
then be <code class="docutils literal notranslate"><span class="pre">the_chosen_string</span> <span class="pre">+</span> <span class="pre">fmt_key</span></code>.</p>
<p>The following example illustrates this:</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [11]: </span><span class="kn">from</span> <span class="nn">psyplot.config.rcsetup</span> <span class="kn">import</span> <span class="n">rcParams</span>
<span class="gp"> ....: </span><span class="kn">from</span> <span class="nn">psyplot.plotter</span> <span class="kn">import</span> <span class="n">Plotter</span><span class="p">,</span> <span class="n">Formatoption</span>
<span class="gp"> ....: </span>
</pre></div>
</div>
<p>First we define our defaultParams, a mapping from default key to the
default value, a validation function, and a description (see the
<a class="reference internal" href="../api/psyplot.config.rcsetup.html#psyplot.config.rcsetup.defaultParams" title="psyplot.config.rcsetup.defaultParams"><code class="xref py py-data docutils literal notranslate"><span class="pre">psyplot.config.rcsetup.defaultParams</span></code></a> dictionary).</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [12]: </span><span class="n">defaultParams</span> <span class="o">=</span> <span class="p">{</span>
<span class="gp"> ....: </span> <span class="s1">'plotter.example_plotter.fmt1'</span><span class="p">:</span> <span class="p">[</span>
<span class="gp"> ....: </span> <span class="mi">1</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">val</span><span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="n">val</span><span class="p">),</span> <span class="s1">'Example formatoption'</span><span class="p">]</span>
<span class="gp"> ....: </span> <span class="p">}</span>
<span class="gp"> ....: </span>
</pre></div>
</div>
<p>Then we update the <a class="reference internal" href="../api/psyplot.config.rcsetup.html#psyplot.config.rcsetup.RcParams.defaultParams" title="psyplot.config.rcsetup.RcParams.defaultParams"><code class="xref py py-attr docutils literal notranslate"><span class="pre">defaultParams</span></code></a> of
the <a class="reference internal" href="../api/psyplot.config.rcsetup.html#psyplot.config.rcsetup.rcParams" title="psyplot.config.rcsetup.rcParams"><code class="xref py py-attr docutils literal notranslate"><span class="pre">psyplot.rcParams</span></code></a> and set the
value</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [13]: </span><span class="n">rcParams</span><span class="o">.</span><span class="n">defaultParams</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">defaultParams</span><span class="p">)</span>
<span class="gp">In [14]: </span><span class="n">rcParams</span><span class="o">.</span><span class="n">update_from_defaultParams</span><span class="p">(</span><span class="n">defaultParams</span><span class="p">)</span>
<span class="gp"> ....: </span><span class="nb">print</span><span class="p">(</span><span class="n">rcParams</span><span class="p">[</span><span class="s1">'plotter.example_plotter.fmt1'</span><span class="p">])</span>
<span class="gp"> ....: </span>
<span class="go">1</span>
</pre></div>
</div>
<p>Now we define a formatoption for our new plotter class and implement it in a
new plotter object.</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [15]: </span><span class="k">class</span> <span class="nc">ExampleFmt</span><span class="p">(</span><span class="n">Formatoption</span><span class="p">):</span>
<span class="gp"> ....: </span> <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="gp"> ....: </span> <span class="k">pass</span>
<span class="gp"> ....: </span>
<span class="gp">In [16]: </span><span class="k">class</span> <span class="nc">ExamplePlotter</span><span class="p">(</span><span class="n">Plotter</span><span class="p">):</span>
<span class="gp"> ....: </span> <span class="c1"># we use our base string, 'plotter.example_plotter.'</span>
<span class="gp"> ....: </span> <span class="n">_rcparams_string</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'plotter.example_plotter.'</span><span class="p">]</span>
<span class="gp"> ....: </span> <span class="c1"># and register a formatoption for the plotter</span>
<span class="gp"> ....: </span> <span class="n">fmt1</span> <span class="o">=</span> <span class="n">ExampleFmt</span><span class="p">(</span><span class="s1">'fmt1'</span><span class="p">)</span>
<span class="gp"> ....: </span>
</pre></div>
</div>
<p>If we now create a new instance of this <code class="docutils literal notranslate"><span class="pre">ExamplePlotter</span></code>, the <code class="docutils literal notranslate"><span class="pre">fmt1</span></code>
formatoption will have a value of <code class="docutils literal notranslate"><span class="pre">1</span></code>, as we defined it in the above
<code class="docutils literal notranslate"><span class="pre">defaultParams</span></code>:</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [17]: </span><span class="n">plotter</span> <span class="o">=</span> <span class="n">ExamplePlotter</span><span class="p">()</span>
<span class="gp">In [18]: </span><span class="nb">print</span><span class="p">(</span><span class="n">plotter</span><span class="p">[</span><span class="s1">'fmt1'</span><span class="p">])</span>
<span class="go">1</span>
<span class="go"># and the default_key is our string in the defaultParams, a combination</span>
<span class="go"># of the _rcparams_string and the formatoption key</span>
<span class="gp">In [19]: </span><span class="nb">print</span><span class="p">(</span><span class="n">plotter</span><span class="o">.</span><span class="n">fmt1</span><span class="o">.</span><span class="n">default_key</span><span class="p">)</span>
<span class="go">plotter.example_plotter.fmt1</span>
<span class="gp">In [20]: </span><span class="nb">print</span><span class="p">(</span><span class="n">plotter</span><span class="o">.</span><span class="n">fmt1</span><span class="o">.</span><span class="n">default</span><span class="p">)</span>
<span class="go">1</span>
</pre></div>
</div>
<p>Changing the value in the <a class="reference internal" href="../api/psyplot.config.rcsetup.html#psyplot.config.rcsetup.rcParams" title="psyplot.config.rcsetup.rcParams"><code class="xref py py-attr docutils literal notranslate"><span class="pre">rcParams</span></code></a>, also
changes the default value for the plotter</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [21]: </span><span class="n">rcParams</span><span class="p">[</span><span class="s1">'plotter.example_plotter.fmt1'</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>
<span class="gp">In [22]: </span><span class="nb">print</span><span class="p">(</span><span class="n">plotter</span><span class="o">.</span><span class="n">fmt1</span><span class="o">.</span><span class="n">default</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
<p>Also, if we subclass this plotter, the default_key will not change</p>
<div class="highlight-ipython notranslate"><div class="highlight"><pre><span></span><span class="gp">In [23]: </span><span class="k">class</span> <span class="nc">SecondPlotter</span><span class="p">(</span><span class="n">ExamplePlotter</span><span class="p">):</span>
<span class="gp"> ....: </span> <span class="c1"># we set a new _rcparams_string</span>
<span class="gp"> ....: </span> <span class="n">_rcparams_string</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'plotter.another_plotter.'</span><span class="p">]</span>
<span class="gp"> ....: </span>
<span class="gp">In [24]: </span><span class="n">plotter</span> <span class="o">=</span> <span class="n">SecondPlotter</span><span class="p">()</span>
<span class="go"># still the same key, although we defined a different _rcparams_string</span>
<span class="gp">In [25]: </span><span class="nb">print</span><span class="p">(</span><span class="n">plotter</span><span class="o">.</span><span class="n">fmt1</span><span class="o">.</span><span class="n">default_key</span><span class="p">)</span>
<span class="go">plotter.example_plotter.fmt1</span>
</pre></div>
</div>
<p>If you’re developing a new plugin you would then have to define the
<code class="docutils literal notranslate"><span class="pre">rcParams</span></code> and <code class="docutils literal notranslate"><span class="pre">defaultParams</span></code> in the <code class="docutils literal notranslate"><span class="pre">plugin.py</span></code> script (see
<a class="reference internal" href="#new-plugins"><span class="std std-ref">Creating new plugins</span></a>) and they will then be automatically implemented in
<a class="reference internal" href="../api/psyplot.config.rcsetup.html#psyplot.config.rcsetup.rcParams" title="psyplot.config.rcsetup.rcParams"><code class="xref py py-attr docutils literal notranslate"><span class="pre">psyplot.rcParams</span></code></a>.</p>
</section>
</section>
</div>
</div>
<!--
SPDX-FileCopyrightText: 2021-2024 Helmholtz-Zentrum hereon GmbH
SPDX-License-Identifier: CC-BY-4.0
-->
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="framework.html" class="btn btn-neutral float-left" title="The psyplot framework" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="../contributing.html" class="btn btn-neutral float-right" title="Contribution and development hints" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>© Copyright 2021-2024 Helmholtz-Zentrum hereon GmbH.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
<div class="footer">
<span class="creativecommons">
<a href="https://creativecommons.org/licenses/by/4.0/" >
<img style="height: 1.5em;" src="../_static/license_logo.png" border="0" alt="Creative Commons License"/>
</a>
This documentation is licensed under
<a href="https://creativecommons.org/licenses/by/4.0/">
CC-BY-4.0
</a>
</span>
</div>
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>