[HN Gopher] Matplotlib Gallery
___________________________________________________________________
Matplotlib Gallery
Author : belter
Score : 51 points
Date : 2021-07-18 14:40 UTC (8 hours ago)
(HTM) web link (matplotlib.org)
(TXT) w3m dump (matplotlib.org)
| jwilber wrote:
| Great library with what may be the most unintuitive, patched-
| together feeing api of any charting library I've used.
| jbay808 wrote:
| Definitely. One of the big problems, for me, is that there are
| at least two completely different interfaces with incompatible
| function names and arguments. While the object-oriented
| interface is frequently recommended, the pyplot interface is
| more commonly seen in stackoverflow questions and answers.
| Official documentation often shows examples only using one or
| the other. So you might have a mostly-functioning Object-
| Oriented plotting script, then wonder something like "how can I
| create another set of y-axis tics going along the right,
| showing temperature in fahrenheit", and only find slightly-
| similar-but-incompatible explanations that use the Pyplot
| interface.
|
| It makes, by example, a pretty strong argument for not allowing
| multiple ways of doing something.
| curiousgal wrote:
| What's the object-oriented interface? I've only ever used
| pyplot l.
| wswope wrote:
| fig, ax = plt.subplots()
|
| then make calls on the Figure and Axes objects.
|
| https://matplotlib.org/stable/api/index.html#usage-patterns
| amelius wrote:
| But note that, while it doesn't expose global state, it
| is still not thread-safe. The documentation only says
| that it "may work" and that there are specific things
| that will certainly crash when used from different
| threads.
|
| https://matplotlib.org/stable/faq/howto_faq.html
| rich_sasha wrote:
| 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 wrote:
| That's a good point. It might be less clear how to find the
| OO function that corresponds to a given imperative command.
| icegreentea2 wrote:
| Kind 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.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/matplo
| tlib.pyplot....) will take you to: 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.
| tryptophan wrote:
| Agreed. I did not understand how terrible it is until I tried
| R's ggplot2.
| krastanov wrote:
| ggplot and matplotlib have drastically different purposes.
| Ggplot is for statistical plots (see seaborn which is built
| on top of matplotlib for another style of statistical plots
| library). Matplotlib has multiple interfaces you can use and
| modern matplotlib code is very consistent and nice to use *if
| you need full control over your plots* (and it does way more
| than just statistical plots). The older matplotlib interfaces
| are indeed a bit of a mess, due to historical reasons.
|
| See bokeh (in python) and makie, gadfly, plots, and
| AlgebraOfGraphics (in julia) for yet more styles of making
| high level plots. But again, matplotlib targets users needing
| more control and less statistics (people build stats and
| other libraries on top of matplotlib though).
| bobbylarrybobby wrote:
| If you need full control over your plots, you should just
| d3, which an insanely sane interface compared to matplotlib
| version_five wrote:
| Matplotlib is like democracy, the worst option except all
| the other options. I do production quality plots for
| technical reports and matplotlib is the only suitable
| python library I've found that gives me the control I need.
| Like you say, there are lots of other libraries that
| combine stats (or other data analysis) and plotting. The
| paradigm I always use is to do the analysis separately, and
| plot the final result focusing on presentation and
| formatting.
|
| Matplotlib is the best I can find for this, despite the
| sometimes clunky interface. GNUplot is also good, but its
| easier to have a native python library.
|
| One more thing I'll say that had heavily biased me, I
| started off with Matlab, and I find that matplotlib is the
| closest to Matlab plotting, which is a lot of why I like
| it.
| [deleted]
___________________________________________________________________
(page generated 2021-07-18 23:01 UTC)