matplotlib.pyplot drawing. 散点图出现按label选颜色:

I draw lots of svg,emf pics this term. So today write down some useful operations about pyplot//plt

1
2
font = {'family': 'Times New Roman', 'weight': 'normal', 'size': 15}
matplotlib.rc('font', **font)

see more:
refto: https://stackoverflow.com/questions/3899980/how-to-change-the-font-size-on-a-matplotlib-plot

散点图出现按label选颜色:

此时使用plt.legend()则会导致大量重复legend信息
加入以下代码:

1
2
3
4
5
6
from collections import OrderedDict
import matplotlib.pyplot as plt

handles, labels = plt.gca().get_legend_handles_labels()
by_label = OrderedDict(zip(labels, handles))
plt.legend(by_label.values(), by_label.keys())

Ref to:https://stackoverflow.com/questions/13588920/stop-matplotlib-repeating-labels-in-legend/13589144#13589144?newreg=343f04f97343416eaab57766f14fbfa2