Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogstools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Max Bittens
ogstools
Commits
fd0573fc
Commit
fd0573fc
authored
1 year ago
by
Florian Zill
Browse files
Options
Downloads
Patches
Plain Diff
plot utils
parent
1ec4941b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ogstools/meshplotlib/utils.py
+38
-0
38 additions, 0 deletions
ogstools/meshplotlib/utils.py
tests/test_meshplotlib.py
+14
-0
14 additions, 0 deletions
tests/test_meshplotlib.py
with
52 additions
and
0 deletions
ogstools/meshplotlib/utils.py
0 → 100644
+
38
−
0
View file @
fd0573fc
from
typing
import
Optional
import
matplotlib.pyplot
as
plt
import
numpy
as
np
def
justified_labels
(
points
:
np
.
ndarray
)
->
list
[
str
]:
"
Formats an array of points to a list of aligned str.
"
def
fmt
(
val
:
float
):
return
f
"
{
val
:
.
2
f
}
"
.
rstrip
(
"
0
"
).
rstrip
(
"
.
"
)
col_lens
=
np
.
max
(
[[
len
(
fmt
(
coord
))
for
coord
in
point
]
for
point
in
points
],
axis
=
0
)
return
[
"
,
"
.
join
(
fmt
(
point
[
i
]).
rjust
(
col_lens
[
i
])
for
i
in
range
(
3
))
for
point
in
points
]
def
get_style_cycler
(
min_number_of_styles
:
int
,
colors
:
Optional
[
Optional
[
list
]]
=
None
,
linestyles
:
Optional
[
list
]
=
None
,
)
->
plt
.
cycler
:
if
colors
is
None
:
colors
=
plt
.
rcParams
[
"
axes.prop_cycle
"
].
by_key
()[
"
color
"
]
if
linestyles
is
None
:
linestyles
=
[
"
-
"
,
"
--
"
,
"
:
"
,
"
-.
"
]
styles_len
=
min
(
len
(
colors
),
len
(
linestyles
))
c_cycler
=
plt
.
cycler
(
color
=
colors
)
ls_cycler
=
plt
.
cycler
(
linestyle
=
linestyles
)
if
min_number_of_styles
<=
styles_len
:
style_cycler
=
c_cycler
[:
styles_len
]
+
ls_cycler
[:
styles_len
]
else
:
style_cycler
=
ls_cycler
*
c_cycler
return
style_cycler
This diff is collapsed.
Click to expand it.
tests/test_meshplotlib.py
+
14
−
0
View file @
fd0573fc
...
@@ -11,6 +11,7 @@ from ogstools.meshplotlib import examples, plot, plot_diff, plot_limit, setup
...
@@ -11,6 +11,7 @@ from ogstools.meshplotlib import examples, plot, plot_diff, plot_limit, setup
from
ogstools.meshplotlib.animation
import
animate
,
save_animation
from
ogstools.meshplotlib.animation
import
animate
,
save_animation
from
ogstools.meshplotlib.levels
import
get_levels
from
ogstools.meshplotlib.levels
import
get_levels
from
ogstools.meshplotlib.plot_features
import
plot_on_top
from
ogstools.meshplotlib.plot_features
import
plot_on_top
from
ogstools.meshplotlib.utils
import
justified_labels
from
ogstools.propertylib
import
Scalar
,
presets
from
ogstools.propertylib
import
Scalar
,
presets
equality
=
partial
(
np
.
testing
.
assert_allclose
,
rtol
=
1e-7
,
verbose
=
True
)
equality
=
partial
(
np
.
testing
.
assert_allclose
,
rtol
=
1e-7
,
verbose
=
True
)
...
@@ -37,6 +38,19 @@ class MeshplotlibTest(unittest.TestCase):
...
@@ -37,6 +38,19 @@ class MeshplotlibTest(unittest.TestCase):
equality
(
get_levels
(
0.0
,
0.0
,
10
),
[
0.0
,
1e-6
])
equality
(
get_levels
(
0.0
,
0.0
,
10
),
[
0.0
,
1e-6
])
equality
(
get_levels
(
1e9
,
1e9
,
10
),
[
1e9
,
1e9
+
1e-6
])
equality
(
get_levels
(
1e9
,
1e9
,
10
),
[
1e9
,
1e9
+
1e-6
])
def
test_justified_labels
(
self
):
points
=
np
.
asarray
(
[
[
x
,
y
,
z
]
for
x
in
np
.
linspace
(
-
1
,
0
,
3
)
for
y
in
np
.
linspace
(
-
10
,
10
,
5
)
for
z
in
np
.
linspace
(
1e-6
,
1e6
,
7
)
]
)
labels
=
justified_labels
(
points
)
str_lens
=
np
.
asarray
([
len
(
label
)
for
label
in
labels
])
self
.
assertTrue
(
np
.
all
(
str_lens
==
str_lens
[
0
]))
def
test_missing_data
(
self
):
def
test_missing_data
(
self
):
"""
Test missing data in mesh.
"""
"""
Test missing data in mesh.
"""
mesh
=
pv_examples
.
load_uniform
()
mesh
=
pv_examples
.
load_uniform
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment