Is there a way of drawing a caption box in matplotlib

Use pyplot.text. Here is some sample code: from matplotlib import pyplot as plt import numpy as np x = np.arange(0,3,.25) y = np.sin(x) txt=””‘ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut … Read more

Matplotlib: simultaneous plotting in multiple threads

Why not just use multiprocessing? As far as I can tell from your description, threading won’t help you much, anyway… Matplotlib already threads so that you can display and interact with multiple figures at once. If you want to speed up batch processing on a multicore machine, you’re going to need multiprocessing regardless. As a … Read more

ImportError: Cannot load backend ‘TkAgg’ which requires the ‘tk’ interactive framework, as ‘headless’ is currently running

What solved the problem for me was to restart my kernel, import the following first: import matplotlib matplotlib.use(‘TKAgg’) Then, import matplotlib.pyplot as plt You probably imported matplotlib with another framework before you tried to change to TKAgg. Restart your kernel.

How to redefine a color for a specific value in a colormap

You can also use set_under which I think makes more semantic sense than using set_bad my_cmap = matplotlib.cm.get_cmap(‘rainbow’) my_cmap.set_under(‘w’) imshow(np.arange(25).reshape(5, 5), interpolation=’none’, cmap=my_cmap, vmin=.001) You can tweak the colorbar to also show the ‘under’ (and the symmetric ‘over’) color using the kwarg extend, see example and docs. For an answer to a duplicate with more … Read more

How to add a text into a Rectangle?

I think you need to use the annotate method of your axes object. You can use properties of the rectangle to be smart about it. Here’s a toy example: import matplotlib.pyplot as plt import matplotlib.patches as mpatch fig, ax = plt.subplots() rectangles = {‘skinny’ : mpatch.Rectangle((2,2), 8, 2), ‘square’ : mpatch.Rectangle((4,6), 6, 6)} for r … Read more

How to surface plot/3d plot from dataframe

.plot_surface() takes 2D arrays as inputs, not 1D DataFrame columns. This has been explained quite well here, along with the below code that illustrates how one could arrive at the required format using DataFrame input. Reproduced below with minor modifications like additional comments. Alternatively, however, there is .plot_trisurf() which uses 1D inputs. I’ve added an … Read more

Spacing between some subplots but not all

When you call update, you’re applying those parameters to all of the subplots in that particular gridspec. If you want to use different parameters for different subplots, you can make multiple gridspecs. However, you’ll need to make sure they are the correct size and don’t overlap. One way do to that is with nested gridspecs. … Read more