r/Python • • Aug 16 '21

Discussion Anyone else despises Matplotlib?

Every time I need to use mpl for a project I die a little inside. The API feels like using a completely different language, I simply can't make a basic plot without having to re-google stuff as everything feels anti intuitive.

Plus, the output bothers me too. Interactive plots feel extremely awkward, and its just wonky

EDIT: Despises working with matplotlib*. I'm thankful such a powerful library exists, and I get that for scientific papers and stuff like that it's great, but damn isn't it painful to use

711 Upvotes

165 comments sorted by

View all comments

Show parent comment

4

u/CutOnBumInBandHere9 Aug 16 '21

If you had to do that now, you can do something like

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-3, 3, 100)
y = x + np.random.rand(100)
plt.scatter(x, y)
ax = plt.gca()
ax.spines[:].set_position('center')

On older versions of matplotlib the last line would have to be replaced by something like

ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
  
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
  
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

So, not impossible, but not the easiest thing in the world either. Don't know why anyone would ever want to eyeball pixels and move axes to approximate positions!