How to display multiple images in one figure correctly? [duplicate]

Here is my approach that you may try: import numpy as np import matplotlib.pyplot as plt w = 10 h = 10 fig = plt.figure(figsize=(8, 8)) columns = 4 rows = 5 for i in range(1, columns*rows +1): img = np.random.randint(10, size=(h,w)) fig.add_subplot(rows, columns, i) plt.imshow(img) plt.show() The resulting image: (Original answer date: Oct 7 … Read more

Adding an arbitrary line to a matplotlib plot in ipython notebook

You can directly plot the lines you want by feeding the plot command with the corresponding data (boundaries of the segments): plot([x1, x2], [y1, y2], color=”k”, linestyle=”-“, linewidth=2) (of course you can choose the color, line width, line style, etc.) From your example: import numpy as np import matplotlib.pyplot as plt np.random.seed(5) x = np.arange(1, … Read more

How to pick a new color for each plotted line within a figure in matplotlib?

I usually use the second one of these: from matplotlib.pyplot import cm import numpy as np #variable n below should be number of curves to plot #version 1: color = cm.rainbow(np.linspace(0, 1, n)) for i, c in zip(range(n), color): plt.plot(x, y, c=c) #or version 2: color = iter(cm.rainbow(np.linspace(0, 1, n))) for i in range(n): c … Read more

Matplotlib – global legend and title aside subplots

Global title: In newer releases of matplotlib one can use Figure.suptitle() method of Figure: import matplotlib.pyplot as plt fig = plt.gcf() fig.suptitle(“Title centered above all subplots”, fontsize=14) Alternatively (based on @Steven C. Howell’s comment below (thank you!)), use the matplotlib.pyplot.suptitle() function: import matplotlib.pyplot as plt # plot stuff # … plt.suptitle(“Title centered above all subplots”, … Read more

Calling pylab.savefig without display in ipython

This is a matplotlib question, and you can get around this by using a backend that doesn’t display to the user, e.g. ‘Agg’: import matplotlib matplotlib.use(‘Agg’) import matplotlib.pyplot as plt plt.plot([1,2,3]) plt.savefig(‘/tmp/test.png’) EDIT: If you don’t want to lose the ability to display plots, turn off Interactive Mode, and only call plt.show() when you are … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)