Fix Python – matplotlib: colorbars and its text labels

I’d like to create a colorbar legend for a heatmap, such that the labels are in the center of each discrete color. Example borrowed from here:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import ListedColormap

#discrete color scheme
cMap = ListedColormap([‘white’, ‘green’, ‘blue’,’red’])


Fix Python – Moving matplotlib legend outside of the axis makes it cutoff by the figure box

I’m familiar with the following questions:
Matplotlib savefig with a legend outside the plot
How to put the legend out of the plot
It seems that the answers in these questions have the luxury of being able to fiddle with the exact shrinking of the axis so that the legend fits.
Shrinking the axes, however, is not an ideal solution because it makes….

Fix Python – Secondary axis with twinx(): how to add to legend?

I have a plot with two y-axes, using twinx(). I also give labels to the lines, and want to show them with legend(), but I only succeed to get the labels of one axis in the legend:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
rc(‘mathtext’, default=’regular’)

fig = plt.figure()
ax = fig.add_subplot(111)

Fix Python – How to change legend size with matplotlib.pyplot

Simple question here: I’m trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I’m using goes something like this:
plot.scatter(k, sum_cf, color=’black’, label=’Sum of Cause Fractions’)
plot.scatter(k, data[:, 0], color=’b’, label=’Dis 1: cf = .6, var = .2′)

Fix Python – How to put the legend outside the plot

I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, as the size of the figure gets reduced.

I want to keep the legend box outside the plot area. (I want the legend to be outside at the right side of the plot area).
Is there anyway….