@@ -413,12 +413,20 @@ Figure commands
413413 Initialise a new figure with the ID `number `.
414414
415415 :param number: The number of the figure. If set to `-1 ` default numbering
416- (increasing from `0 ` on) is used.
417- :return: The number of the figure.
416+ (increasing from `0 ` on) is used
417+ :return: The number of the figure
418+
419+ .. _mpl_fignum_exists : https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.fignum_exists.html
418420
419421.. cpp :function ::
420422 inline bool fignum_exists (long number)
421423
424+ .. image :: ../img/matplotlib_icon.png
425+ :align: right
426+ :width: 20px
427+ :height: 20px
428+ :target: mpl_fignum_exists_
429+
422430 Check if a figure of given number exists.
423431
424432 :param number: The number of the figure
@@ -427,11 +435,10 @@ Figure commands
427435.. cpp :function ::
428436 inline void figure_size (size_t w, size_t h)
429437
430- Set the figure size to `w ` x `h ` inches.
431-
432- :param w: The width of the figure in inches
433- :param h: The height of the figure in inches
438+ Call `plt::figure() ` and set the figure size to `w ` x `h ` pixels.
434439
440+ :param w: The width of the figure in pixels
441+ :param h: The height of the figure in pixels
435442
436443.. _mpl_legend : https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.legend.html
437444
@@ -446,25 +453,28 @@ Figure commands
446453 :height: 20px
447454 :target: mpl_legend_
448455
449- Set the figure legend.
456+ Enable the figure legend.
450457
451458 :tparam Vector: vector-like type, see :cpp:type: `Vector `, defaults
452459 to `std::vector<double> `
453460 :param loc: The location of the legend. May be any of:
454461 "best", "upper left", "upper center", "upper left",
455- "center left", "center", "center right" (== "right"),
462+ "center left", "center", "center right" (= "right"),
456463 "lower left", "lower center", "lower right"
457- :param bbox_to_anchor: If set to a vector of length 2 or 4 it
464+ :param bbox_to_anchor:
465+ If set to a vector of length 2 or 4 it
458466 specifies the location (and size) of the legend's bounding box.
459467 Format is (`x `, `y `) or (`x `, `y `, `width `, `height `).
460468 The coordinates are interpreted in the same units as the
461469 plot axes (thus no normalised coordinates)
462470
463- .. code-block :: cpp
471+ ** Example **
464472
465- // Put the legend in the center of the bottom right quadrant.
466- // First argument: loc, second: bbox_to_anchor
467- plt::legend("center", {0.5, 0, 0.5, 0.5});
473+ .. code-block :: cpp
474+
475+ // Put the legend in the center of the bottom right quadrant.
476+ // First argument: loc, second: bbox_to_anchor
477+ plt::legend("center", {0.5, 0, 0.5, 0.5});
468478
469479
470480 .. _mpl_xlim : https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.xlim.html
@@ -581,3 +591,83 @@ Figure commands
581591 `image ` `scaled ` with axis limits equal to data limits.
582592 `square ` Square plot; similar to `scaled `, but initially forcing same x- and y-axis length.
583593 ========= ================================================
594+
595+ .. _mpl_savefig : https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html
596+
597+ .. cpp :function ::
598+ inline void savefig (const std::string &filename, \
599+ const std::map<std::string, std::string> &keywords = {})
600+
601+ .. image :: ../img/matplotlib_icon.png
602+ :align: right
603+ :width: 20px
604+ :height: 20px
605+ :target: mpl_savefig_
606+
607+ Save the current figure.
608+
609+ Supported file types depend on the user backend, but usually
610+ contain `pdf `, `eps ` and `png `. To find all supported formats try
611+
612+ .. code-block :: bash
613+
614+ $ python3
615+ >>> import matplotlib.pyplot as plt
616+ >>> plt.gcf().canvas.get_supported_filetypes_grouped ()
617+
618+ :param filename: Save the figure to `filename ` (must contain file format)
619+ :param keywords: Additional keywords, see `Other Parameters ` `here <mpl_savefig >`_ for a complete list
620+
621+ **Examples **
622+
623+ .. code-block :: cpp
624+
625+ plt::plot(x, y);
626+ plt::savefig("plot.pdf");
627+
628+ Always the current state of the figure is stored.
629+
630+ .. code-block :: cpp
631+
632+ plt::plot(time, apple_sales);
633+ plt::savefig("sales.pdf"); // contains only apple_sales
634+ plt::plot(time, kiwi_sales);
635+ plt::savefig("sales.pdf"); // contains apple and kiwi sales
636+
637+ Calling `plt::show() ` clears the plot!
638+
639+ .. code-block :: cpp
640+
641+ plt::plot(x, y);
642+ plt::show();
643+ plt::savefig("is_this_empty.pdf"); // yes, this will be empty
644+
645+ plt::plot(x, y);
646+ plt::savefig("this_isnt_empty.pdf"); // always call savefig *before* show
647+ plt::show();
648+
649+ Optimally use the available canvas space with `{{"bbox_inches", "tight"}} `.
650+ This can be useful if e.g. the axis labels are too far outside and get cut off.
651+
652+ .. code-block :: cpp
653+
654+ plt::savefig("fig.pdf", {{"bbox_inches", "tight"}});
655+
656+
657+ .. _mpl_show : https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.show.html
658+
659+ .. cpp :function ::
660+ inline void show (const bool block = true)
661+
662+ .. image :: ../img/matplotlib_icon.png
663+ :align: right
664+ :width: 20px
665+ :height: 20px
666+ :target: mpl_show_
667+
668+ Display the figure.
669+
670+ :param block: If true, the execution of the code is stopped until the
671+ displayed figure is closed. Otherwise the code is not stopped.
672+ Depending on the backend, figures might not get displayed
673+ at all.
0 commit comments