Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

matplotlib legend from scratch

import matplotlib.lines as mlines
import matplotlib.pyplot as plt

blue_star = mlines.Line2D([], [], color='blue', marker='*', linestyle='None',
                          markersize=10, label='Blue stars')
red_square = mlines.Line2D([], [], color='red', marker='s', linestyle='None',
                          markersize=10, label='Red squares')
purple_triangle = mlines.Line2D([], [], color='purple', marker='^', linestyle='None',
                          markersize=10, label='Purple triangles')

plt.legend(handles=[blue_star, red_square, purple_triangle])

plt.show()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #matplotlib #legend #scratch
ADD COMMENT
Topic
Name
8+4 =