I'm using the command :
axins.clabel(c, levls, fontsize=4, fmt='%4.2f', colors= 'white')
to generate labels for my contours, I'd like them to be white (colors='white' works) with a red background, I can't find whether it's possible or not to specify a background color for them ?
The default color scheme of Matplotlib contour and filled contour plots can be modified. A general way to modify the color scheme is to call Matplotlib's plt. get_cmap() function that outputs a color map object.
If True , contour labels will be placed manually using mouse clicks. Click the first button near a contour to add a label, click the second button (or potentially both mouse buttons at once) to finish adding labels.
MatPlotLib with Python Contour plots (sometimes called Level Plots) are a way to show a three-dimensional surface on a two-dimensional plane. It graphs two predictor variables X Y on the y-axis and a response variable Z as contours. These contours are sometimes called the z-slices or the iso-response values.
I am several years late to the part party, but this answer is still coming up on Google so here is the solution I hacked inspired by @pelson's answer.
If you set up the contour plot as:
CS = ax.contour(X, Y, Z)
clabels = ax.clabel(CS)
Then you can simply update the background colours using
[txt.set_backgroundcolor('white') for txt in clabels]
However the bounding box (bbox
) is quite large and often obscures other features unnecessarily. So it is better to update the bbox
directly:
[txt.set_bbox(dict(facecolor='white', edgecolor='none', pad=0)) for txt in clabels]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With