Improve subplot size/spacing with many subplots

Please review matplotlib: Tight Layout guide and try using matplotlib.pyplot.tight_layout, or matplotlib.figure.Figure.tight_layout As a quick example: import matplotlib.pyplot as plt fig, axes = plt.subplots(nrows=4, ncols=4, figsize=(8, 8)) fig.tight_layout() # Or equivalently, “plt.tight_layout()” plt.show() Without Tight Layout With Tight Layout

Hiding axis text in matplotlib plots

Instead of hiding each element, you can hide the whole axis: frame1.axes.get_xaxis().set_visible(False) frame1.axes.get_yaxis().set_visible(False) Or, you can set the ticks to an empty list: frame1.axes.get_xaxis().set_ticks([]) frame1.axes.get_yaxis().set_ticks([]) In this second option, you can still use plt.xlabel() and plt.ylabel() to add labels to the axes.

When to use cla(), clf() or close() for clearing a plot in matplotlib?

They all do different things, since matplotlib uses a hierarchical order in which a figure window contains a figure which may consist of many axes. Additionally, there are functions from the pyplot interface and there are methods on the Figure class. I will discuss both cases below. pyplot interface pyplot is a module that collects … Read more

Changing the tick frequency on the x or y axis

You could explicitly set where you want to tick marks with plt.xticks: plt.xticks(np.arange(min(x), max(x)+1, 1.0)) For example, import numpy as np import matplotlib.pyplot as plt x = [0,5,9,10,15] y = [0,1,2,3,4] plt.plot(x,y) plt.xticks(np.arange(min(x), max(x)+1, 1.0)) plt.show() (np.arange was used rather than Python’s range function just in case min(x) and max(x) are floats instead of ints.) … Read more