import os
setup_script = os.path.join(os.environ['ENV_JUPYTER_SETUPS_DIR'], 'setup_sci_env_basic.py')
%run $setup_script

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

ignore_warnings()

"""
Explanation: Legend customization
References:
- https://matplotlib.org/users/legend_guide.html
- https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.legend
- https://jakevdp.github.io/PythonDataScienceHandbook/04.06-customizing-legends.html
| Location string | Location code |
| ------------ | --- |
| best         |  0  |
| upper right  |  1  |
| upper left   |  2  |
| lower left   |  3  |
| lower right  |  4  |
| right        |  5  |
| center left  |  6  | 
| center right |  7  |
| lower center |  8  |
| upper center |  9  | 
| center       | 10  |
https://github.com/denglert/toolbox/tree/master/python/jupyter
End of explanation
"""


red_patch = mpatches.Patch(color='red', label='The red data')

blue_line = mlines.Line2D([], [], color='blue', marker='*',
                          markersize=15, label='Blue stars')

legend_handles = [red_patch, blue_line]

f,a = plt.subplots()
leg = a.legend(handles=legend_handles)
# - Note: you can also call plt.legend(..)

"""
Explanation: Custom legend markers
End of explanation
"""


f,a = plt.subplots()
a.plot([1,2,3], label="test1")
# Place a legend above this subplot, expanding itself to
# fully use the given bounding box.
leg = a.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
           ncol=2, mode="expand", borderaxespad=0.)

"""
Explanation: Legend position
Placing above
End of explanation
"""


f,a = plt.subplots()
a.plot([1,2,3], label="test1")
# Place a legend above this subplot, expanding itself to
# fully use the given bounding box.
a.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

"""
Explanation: Placing to the right
End of explanation
"""


