# matplotlib

## Matplotlib and Pyplot.close() not releasing memory? – backend related Qt4Agg

I think the reason it is doing this is because as it goes through all of the different graphs it then runs out of memory probably because it isn’t releasing it properly. Why don’t you try creating about 3 or so programs each of which do a few graphs instead of one program doing all …

## Understanding matplotlib: plt, figure, ax(arr)?

pyplot is the ‘scripting’ level API in matplotlib (its highest level API to do a lot with matplotlib). It allows you to use matplotlib using a procedural interface in a similar way as you can do it with Matlab. pyplot has a notion of ‘current figure’ and ‘current axes’ that all the functions delegate to …

## Matplotlib Error: “figure includes Axes that are not compatible with tight_layout”

In my experience, plt.tight_layout doesn’t always work but plt.savefig(‘fig.png’,bbox_inches=”tight”) does. In addition, you don’t need the former after using the latter and I have come to the conclusion after some pretty extensive testing of it.

## Plotting results of Pandas GroupBy

I think @herrfz hit all the high points. I’ll just flesh out the details: import pandas as pd import numpy as np import matplotlib.pyplot as plt sin = np.sin cos = np.cos pi = np.pi N = 100 x = np.linspace(0, pi, N) a = sin(x) b = cos(x) df = pd.DataFrame({ ‘A’: [True]*N + …

## make matplotlib plotting window pop up as the active one

For me (OSX 10.10.2, Matplotlib 1.4.3), what works is changing the matplotlib backend to TkAgg. Before importing pyplot or anything, go: import matplotlib matplotlib.use(‘TkAgg’) Plot windows now pop-up, and can be Command-Tab’ed to.

## Why is set_xlim() not setting the x-limits in my figure?

Out of curiosity, what about switching in the old xmin and xmax? fig=plt.figure() ax=fig.add_subplot(111) ax.plot(x_data,y_data) ax.set_xlim(xmin=0.0, xmax=1000) plt.savefig(filename)

## Using %matplotlib notebook after %matplotlib inline in Jupyter Notebook doesn’t work

You just have the wrong order of your commands. A backend should be set before importing pyplot in jupyter. Or in other words, after changing the backend, pyplot needs to be imported again. Therefore call %matplotlib … prior to importing pyplot. In first cell: %matplotlib inline import matplotlib.pyplot as plt plt.plot([1,1.6,3]) In second cell: %matplotlib …

## How to plot 1-d data at given y-value with pylab

Staven already edited his post to include how to plot the values along y-value 1, but he was using Python lists. A variant that should be faster (although I did not measure it) only uses numpy arrays: import numpy as np import matplotlib.pyplot as pp val = 0. # this is the value where you …

## Retrieve XY data from matplotlib figure [duplicate]

This works: In [1]: import matplotlib.pyplot as plt In [2]: plt.plot([1,2,3],[4,5,6]) Out[2]: [<matplotlib.lines.Line2D at 0x30b2b10>] In [3]: ax = plt.gca() # get axis handle In [4]: line = ax.lines[0] # get the first line, there might be more In [5]: line.get_xdata() Out[5]: array([1, 2, 3]) In [6]: line.get_ydata() Out[6]: array([4, 5, 6]) In [7]: line.get_xydata() …