Heatmap with text in each cell with matplotlib’s pyplot

You need to add all the text by calling axes.text(), here is an example: import numpy as np import matplotlib.pyplot as plt title = “ROC’s AUC” xlabel= “Timeshift” ylabel=”Scales” data = np.random.rand(8,12) plt.figure(figsize=(12, 6)) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) c = plt.pcolor(data, edgecolors=”k”, linewidths=4, cmap=’RdBu’, vmin=0.0, vmax=1.0) def show_values(pc, fmt=”%.2f”, **kw): from itertools import izip pc.update_scalarmappable() ax … Read more

Getting xkcd plots using matplotlib

To get it working, you need matplotlib 1.3.1 (it won’t work with matplotlib 1.3.0 or earlier) sudo pip install matplotlib –upgrade font Humor Sans download from here or here, install (on OS X you open it and click Install) remove the matplotlib font cache (as suggested by DanHickstein in matplotlib/issues/2269) rm ~/.matplotlib/fontList.cache Now, execute the … Read more

matplotlib ticks thickness

A simpler way is to use the set_tick_params function of axis objects: ax.xaxis.set_tick_params(width=5) ax.yaxis.set_tick_params(width=5) Doing it this way means you can change this on a per-axis basis with out worrying about global state and with out making any assumptions about the internal structure of mpl objects. If you want to set this for all the … Read more

Matplotlib, Consistent font using latex

To make the tex-style/mathtext text look like the regular text, you need to set the mathtext font to Bitstream Vera Sans, import matplotlib matplotlib.rcParams[‘mathtext.fontset’] = ‘custom’ matplotlib.rcParams[‘mathtext.rm’] = ‘Bitstream Vera Sans’ matplotlib.rcParams[‘mathtext.it’] = ‘Bitstream Vera Sans:italic’ matplotlib.rcParams[‘mathtext.bf’] = ‘Bitstream Vera Sans:bold’ matplotlib.pyplot.title(r’ABC123 vs $\mathrm{ABC123}^{123}$’) If you want the regular text to look like the mathtext … Read more

Matplotlib – sequence is off when using plt.imshow()

It seems you are using Juypter notebook. This always shows any autogenerated output (like the matplotlib figures) last in the output. You may use IPython.display.display to display the figures at the position of the output where they belong. import matplotlib.pyplot as plt import numpy as np from IPython.display import display images = [np.random.rayleigh((i+1)/8., size=(180, 200, … Read more

draw grid lines over an image in matplotlib

You will need the python imaging library (PIL) installed. (See here https://pypi.python.org/pypi/PIL). See these answers for examples of ways to install PIL: answer 1, answer 2 Right, with that installed, the following code should do what you ask for: import matplotlib.pyplot as plt import matplotlib.ticker as plticker try: from PIL import Image except ImportError: import … Read more