Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Boeckenhoff
tfields
Commits
e0527b47
Commit
e0527b47
authored
Apr 26, 2019
by
Daniel Boeckenhoff
Browse files
mpl set_legend
parent
bacad5bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
tfields/lib/util.py
View file @
e0527b47
...
...
@@ -67,6 +67,7 @@ def multi_sort(array, *others, **kwargs):
method (function): sorting function. Default is 'sorted'
...: further arguments are passed to method. Default rest is
'key=array[0]'
reversed (bool): wether to reverse the results or not
Examples:
>>> from tfields.lib.util import multi_sort
>>> multi_sort([1,2,3,6,4], [1,2,3,4,5])
...
...
@@ -79,10 +80,24 @@ def multi_sort(array, *others, **kwargs):
>>> multi_sort([1,2,3,6,4], [1,2,3,4,5], [6,5,4,3,2])
[[1, 2, 3, 4, 6], [1, 2, 3, 5, 4], [6, 5, 4, 2, 3]]
Reverse argument
>>> multi_sort([1,2,3,6,4], [1,2,3,4,5], [6,5,4,3,2], reverse=True)
[[6, 4, 3, 2, 1], [4, 5, 3, 2, 1], [3, 2, 4, 5, 6]]
"""
method
=
kwargs
.
pop
(
'method'
,
None
)
if
method
is
None
:
method
=
sorted
if
'key'
not
in
kwargs
:
kwargs
[
'key'
]
=
lambda
pair
:
pair
[
0
]
return
[
list
(
x
)
for
x
in
zip
(
*
method
(
zip
(
array
,
*
others
),
**
kwargs
))]
reverse
=
kwargs
.
pop
(
'reverse'
,
False
)
if
not
reverse
:
cast_type
=
list
else
:
cast_type
=
lambda
x
:
list
(
reversed
(
x
))
return
[
cast_type
(
x
)
for
x
in
zip
(
*
method
(
zip
(
array
,
*
others
),
**
kwargs
))]
if
__name__
==
'__main__'
:
import
doctest
doctest
.
testmod
()
tfields/plotting/mpl.py
View file @
e0527b47
...
...
@@ -697,9 +697,30 @@ def set_legend(axis, artists, **kwargs):
for
artist
in
artists
:
if
isinstance
(
artist
,
list
):
handles
.
append
(
artist
[
0
])
elif
isinstance
(
artist
,
tuple
):
tuple_handle
=
tuple
()
for
sub_artist
in
artist
:
if
isinstance
(
sub_artist
,
list
):
tuple_handle
+=
(
sub_artist
[
0
],)
else
:
tuple_handle
+=
(
sub_artist
,)
handles
.
append
(
tuple_handle
)
else
:
handles
.
append
(
artist
)
if
labels
is
None
and
any
([
isinstance
(
h
,
tuple
)
for
h
in
handles
]):
labels
=
[]
for
h
in
handles
:
if
isinstance
(
h
,
tuple
):
sub_labels
=
[
sub_h
.
get_label
()
for
sub_h
in
h
]
label
=
sub_labels
[
0
]
for
sub_label
in
sub_labels
[
1
:]:
if
not
sub_label
.
startswith
(
'_'
):
label
+=
sub_label
else
:
label
=
h
.
get_label
()
labels
.
append
(
label
)
if
table
and
labels
is
None
and
ncol
is
None
:
table_title
=
kwargs
.
pop
(
'table_title'
,
''
)
labels
=
np
.
array
([
h
.
get_label
()
for
h
in
handles
])
...
...
tfields/plotting/tfields.mplstyle
View file @
e0527b47
...
...
@@ -35,9 +35,4 @@ image.cmap: viridis
text.usetex : True
font.family : serif
font.size : 40 # 20 was a duplicate definition
# mathtext.fontset = 'custom'
# mathtext.rm = 'Bitstream Vera Sans'
# mathtext.it = 'Bitstream Vera Sans:italic'
# mathtext.bf = 'Bitstream Vera Sans:bold'
# mathtext.fontset = 'stix'
# font.family = 'STIXGeneral'
text.latex.preamble : \usepackage{amsmath} # for \text etc
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment