Difficulty To Plot Legend For A Color Bar In Python 3.6
I have 3 colors (ccc) for 3 different types of rock (d2) and I would like to plot a legend with rectangles for my color bar. I already searched about it, but couldn't find the righ
Solution 1:
If I understood correctly, you want three legend handles, one for each colored stone. This can be done by adding custom legend handles using mpatches
import numpy as np
import pandas as pd
import matplotlib.colors as colors
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches # <-- Add thisimport
# Your code here
hands = []
for k, col in zip(d2.keys(), ccc):
hands.append(mpatches.Patch(color=col, label=k))
plt.legend(handles=hands, loc=(1.05, 0.5), fontsize=18)
Post a Comment for "Difficulty To Plot Legend For A Color Bar In Python 3.6"