Search This Blog

Saturday, April 2, 2011

Matplotlib: How to insert colored rectangle inside a label

Matplotlib: How to insert colored rectangle inside a label


import matplotlib
matplotlib.use("TKAGG")
import matplotlib.pyplot as pyplot
import mpl_toolkits.mplot3d

figure = pyplot.figure()
figure.subplots_adjust(bottom=0.25, top=0.75)
axes = figure.gca(projection='3d')
xLabel = axes.set_xlabel('X', fontsize=14, fontweight='bold', color='b')
yLabel = axes.set_ylabel('Y',fontsize=14, fontweight='bold', color='r')
zLabel = axes.set_zlabel('Z',fontsize=14, fontweight='bold', color='g')


x = pyplot.Rectangle((0, 0), 0.1, 0.1,fc='b')
y = pyplot.Rectangle((0, 0), 0.1, 0.1,fc='r')
z = pyplot.Rectangle((0, 0), 0.1, 0.1,fc='g')

handles, labels = axes.get_legend_handles_labels()
axes.legend((x,y,z),("XXXXXX","YYYYY","ZZZZZZ"),'best')


plot = axes.plot([1,2,3],[1,2,3])


pyplot.show()

No comments: