3 ms·
I got my head around it eventually. Anything imperative that implicitly operates on the current figure/axes just calls the OO method on gcf / gca (get current f
by rich_sasha 5y ago
I got my head around it eventually. Anything imperative that implicitly operates on the current figure/axes just calls the OO method on gcf / gca (get current figure / axes).
I often use the imperative API as it’s less typing often, and I do a lot of throwaway plotting code. But some functionality only exists in the OO interface. Then it’s an easy trip to gca().my_oo_function() and you recovered the imperative version.
- jbay808 5y agoThat's a good point. It might be less clear how to find the OO function that corresponds to a given imperative command.
- icegreentea2 5y agoKind of a crappy answer, but just read the source. pyplot is defined in a single file, so it's pretty search to search (for example here: https://matplotlib.org/stable/_modules/matplotlib/pyplot.html https://matplotlib.org/stable/_modules/matplotlib/pyplot.htm...). Or just clicky-click on 'source' link on the pyplot doc page for a call (for example: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.axhspan.html https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot....) will take you to: https://matplotlib.org/stable/_modules/matplotlib/pyplot.html#axhspan https://matplotlib.org/stable/_modules/matplotlib/pyplot.htm... And for most (not all) of the functions, it's an easy read to figure out the OO call.