[HN Gopher] Matplotlib
       ___________________________________________________________________
        
       Matplotlib
        
       Author : tosh
       Score  : 48 points
       Date   : 2023-11-12 15:06 UTC (7 hours ago)
        
 (HTM) web link (matplotlib.org)
 (TXT) w3m dump (matplotlib.org)
        
       | rnadomvirlabe wrote:
       | What about it? Are you trying to point to something specific?
        
         | rschiavone wrote:
         | Probably it's their favorite library?!
        
         | tosh wrote:
         | I haven't used matplotlib in a while (also because I wasn't
         | fluid with it) and now am using it regularly in Code
         | Interpreter w/ GPT-4.
         | 
         | Now I'm thinking there must be many more libraries that are now
         | "in reach" for me for casual use which weren't just a few weeks
         | ago.
        
       | fsh wrote:
       | By far my favorite feature of matplotlib is that it produces
       | readable and accessible plots by default. Font sizes and
       | linewidths are not too small, the default color palette is
       | colorblind-friendly, and the default colormaps are perceptually
       | uniform. Other software (for example Matlab and Mathematica) have
       | absolutely terrible defaults and require a lot of fiddling to get
       | the plots right.
        
         | qwertox wrote:
         | My only issue with it is that you need a lot of tweaking to get
         | a compact layout. Other than that, it's a key part of what
         | makes Python such an incredibly useful language.
        
         | hughess wrote:
         | That fiddling used to drive me nuts in any of the tools I used
         | to work with. It's part of the problem I'm trying to solve with
         | my current open source project (evidence.dev) where we're
         | tackling viz-as-code. You might find it interesting.
         | 
         | Previous HN discussions:
         | 
         | https://news.ycombinator.com/item?id=35645464 (97 comments)
         | 
         | https://news.ycombinator.com/item?id=28304781 (91 comments)
        
         | apwheele wrote:
         | IMO the font size is still too small (ditto for pretty much all
         | stat software). But matplotlib makes it quite easy to change
         | the default look, here is mine:                   import
         | matplotlib                  theme = {'axes.grid': True,
         | 'grid.linestyle': '--',                  'legend.framealpha':
         | 1,                  'legend.facecolor': 'white',
         | 'legend.shadow': True,                  'legend.fontsize': 14,
         | 'legend.title_fontsize': 16,
         | 'xtick.labelsize': 14,                  'ytick.labelsize': 14,
         | 'axes.labelsize': 16,                  'axes.titlesize': 20,
         | 'figure.dpi': 100}
         | matplotlib.rcParams.update(theme)
        
         | ithinkso wrote:
         | Tangential but a thing about defaults - when I was at uni, in a
         | lot of labs we were doing data analysis and plotting in
         | something called Origin. I absolutely loved the defaults there,
         | to this day I can recognize if it was plotted using origin and
         | I had visceral reaction if I'd see something done in Excel.
         | Sane defaults are very important and I'm not sure why they are
         | often afterthoughts
        
         | mpetroff wrote:
         | > the default color palette is colorblind-friendly
         | 
         | No, it very much isn't. The second and third colors, the orange
         | and the green, look extremely similar to protanopes (red
         | deficiency). Fortunately, there's a plan to fix this for
         | Matplotlib 4.0.
        
       | juujian wrote:
       | ggplot > madplitlib, cmm
        
         | SJetKaran wrote:
         | Yep! even started using python clone - plotnine
        
       | theodpHN wrote:
       | Matplotlib is amazing and nice to have when you need it but can
       | be way too complicated for the average user and visualization.
       | Most users' needs, I think, would be better served by something
       | like Plotly Express or other higher-level dataviz packages (for
       | visualizations-thru-code) and Tableau, PowerBI, and Excel (for
       | interactive WYSIWYG dataviz).
        
         | terminous wrote:
         | People don't seem to understand that matplotlib is the lower-
         | level backend/API and not really intended to be a visualization
         | interface for the average user. It's a power tool. Matplotlib's
         | users are other python developers making more high-level
         | visualization libraries, like seaborn, pandas (df.plot()),
         | plotly, ggplot (the python port/version). If you know the
         | matplotlib API, then you can directly modify figures from
         | seaborn, etc.
        
       | esafak wrote:
       | Not my favorite library but it gets the job done.
        
         | jruohonen wrote:
         | Ditto. Awfully convoluted compared to, say, R.
        
           | hewlett wrote:
           | odd how it's still the de facto standard python library for
           | plots despite much better libraries like ggplot or plotly
        
             | tryptophan wrote:
             | Plotly might just be one of the libraries that manages to
             | make documentation less readable than matplotlib. API
             | reference consists of 90% autogenerated doc trash 90 pages
             | long.
        
       | mitthrowaway2 wrote:
       | It's a great library. I only wish that it didn't have two
       | completely different, incompatible interfaces to muddy the
       | documentation, examples, and SO answer threads.
        
         | kzrdude wrote:
         | By which you mean these I think?
         | 
         | 1. the pyplot API (the old one, that is designed to mimic
         | MATLAB - it has functions like plot() and xlabel()).
         | 
         | 2. The Axes API - fig, ax = plt.subplots(); then call
         | ax.plot(), ax.set_xlabel() and so on
         | 
         | One should always prefer the Axes way of doing it, it's
         | refactorable and uses less hidden global state.
        
           | kragen wrote:
           | generally when i'm using matplotlib instead of d3 it's
           | because i'm less concerned about things like refactorability
           | and hidden global state than about getting some data points
           | on the screen in as few keystrokes as possible; %pylab inline
           | and the pyplot api are far superior for that
           | 
           | i wish the axes api didn't exist
        
             | kzrdude wrote:
             | And when I use matplotlib it's to clean up some non-default
             | tweaks to seaborn plots. Refactorability here means that
             | it's easy to go from one plot into one that's split into
             | facets (multiple subplots etc.)
        
               | kragen wrote:
               | true, the subplot api is especially painful because i
               | have to edit each line of code i copy-paste to give it a
               | different subplot number
        
           | mitthrowaway2 wrote:
           | > One should always prefer the Axes way of doing it, it's
           | refactorable and uses less hidden global state.
           | 
           | I fully agree, but half the time you're looking up how to do
           | something, you find methods documented using the other
           | approach, with slightly different method names that don't
           | even have an alias in the axes API. In fact those are usually
           | the ones you find, because people answering SO questions seem
           | to prefer the brevity.
        
         | wenc wrote:
         | The old API was meant to mimic MATLAB. It's in the name -- the
         | "mat" in "matplotlib" refers to MATLAB. And yes, those of us
         | who were brought up on MATLAB gravitated toward it in the early
         | days because it was so familiar. For better or worse, MATLAB
         | was and still a popular in academia (less so these days, but
         | still being used especially in control engineering).
         | 
         | MATLAB's plotting is not the best, but it's familiar to MATLAB
         | legacy folks, who made up many of the early folks who moved
         | over to Numpy, Matplotlib, SciPy. It was a bridge.
        
       | aborsy wrote:
       | Pgfplots produces highest quality plots that I have seen.
        
         | kragen wrote:
         | can you provide some links to examples so we can see what you
         | mean
        
         | terminous wrote:
         | How is this relevant? Pgfplots isn't even a matplotlib
         | competitor really, they're completely different in terms of use
         | cases and ecosystems.
        
         | fsh wrote:
         | I find Pgfplots quite hacky since TeX is really not made for
         | handling data (it doesn't even support floating-point
         | arithmetic). A much cleaner solution is to enable LaTeX text
         | rendering in Matplotlib
         | (https://matplotlib.org/stable/users/explain/text/usetex.html).
         | In this way, TeX is used for what it _is_ good at (text
         | rendering), and everything else is handled by Matplotlib.
        
       | hurryer wrote:
       | Bokeh has a much more sensible API, and it generates an
       | interactive HTML plot by default.
       | 
       | Unfortunately it's missing quite a few specialized plots from
       | matplotlib, in particular the popular histogram plot is strangely
       | difficult to draw.
        
         | rich_sasha wrote:
         | Bokeh requires a lot more typing to do the same thing. Also,
         | for interactive work, I often want the GUI, not a webpage with
         | the plot on it.
        
       | syntaxing wrote:
       | I always wondered how different Matplotlib would have been if
       | John Hunter didn't die so young. His passing was right near the
       | boom of Python too.
        
       | MengerSponge wrote:
       | "Artist" in Matplotlib - something I wanted to know before
       | spending tremendous hours on googling how-tos. - DEV
       | 
       | This looks like a really nice explainer
       | https://dev.to/skotaro/artist-in-matplotlib---something-i-wa...
        
       ___________________________________________________________________
       (page generated 2023-11-12 23:01 UTC)