matplotlib legend location numbers
Question:
I am beginning to use Python for my scientific computing, and I am really liking it a lot, however I am confused by a feature of the matplotlib.pylab.legend function. In particular, the location feature allows one to specifiy the location of their legend using numbers, following this scheme:
- 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
Does anyone know why you wouldn’t use the ordering on the numpad? I.e. center — 5, upper right — 9, etc.
I am just curious if anyone knows.
Answers:
The docs show this example:
legend( ('label1', 'label2', 'label3'), loc='upper left')
Presumably, you could write loc=2
, but why would you? It’s much more readable to use the English word.
As to why they didn’t enumerate the values to align with the numeric keypad, I presume they weren’t thinking about the numeric keypad at the time.
Edit: It’s worth including here the full text of Joe Kington‘s comment:
Actually, they were deliberately mimicking matlab’s behavior at the
time. See the “obsolete location values” section in the documentation
for MATLAB’s legend
: mathworks.com/help/techdoc/ref/legend.html
I am beginning to use Python for my scientific computing, and I am really liking it a lot, however I am confused by a feature of the matplotlib.pylab.legend function. In particular, the location feature allows one to specifiy the location of their legend using numbers, following this scheme:
- 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
Does anyone know why you wouldn’t use the ordering on the numpad? I.e. center — 5, upper right — 9, etc.
I am just curious if anyone knows.
The docs show this example:
legend( ('label1', 'label2', 'label3'), loc='upper left')
Presumably, you could write loc=2
, but why would you? It’s much more readable to use the English word.
As to why they didn’t enumerate the values to align with the numeric keypad, I presume they weren’t thinking about the numeric keypad at the time.
Edit: It’s worth including here the full text of Joe Kington‘s comment:
Actually, they were deliberately mimicking matlab’s behavior at the
time. See the “obsolete location values” section in the documentation
for MATLAB’slegend
: mathworks.com/help/techdoc/ref/legend.html