Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
36
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rdm-software
SaQC
Commits
cfcf8a99
Commit
cfcf8a99
authored
5 years ago
by
David Schäfer
Browse files
Options
Downloads
Patches
Plain Diff
some cleanups
parent
4e728f61
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
saqc/lib/plotting.py
+19
-24
19 additions, 24 deletions
saqc/lib/plotting.py
with
19 additions
and
24 deletions
saqc/lib/plotting.py
+
19
−
24
View file @
cfcf8a99
...
...
@@ -41,6 +41,10 @@ def _plot(
# todo: try catch warn (once) return
# only import if plotting is requested by the user
import
matplotlib
as
mpl
import
matplotlib.pyplot
as
plt
from
pandas.plotting
import
register_matplotlib_converters
# needed for datetime conversion
register_matplotlib_converters
()
if
not
interactive_backend
:
# Import plot libs without interactivity, if not needed. This ensures that this can
...
...
@@ -49,13 +53,8 @@ def _plot(
mpl
.
use
(
"
Agg
"
)
else
:
mpl
.
use
(
"
TkAgg
"
)
from
matplotlib
import
pyplot
as
plt
# needed for datetime conversion
from
pandas.plotting
import
register_matplotlib_converters
register_matplotlib_converters
()
if
not
isinstance
(
varname
,
(
list
,
set
)):
if
np
.
isscalar
(
varname
):
varname
=
[
varname
]
varname
=
set
(
varname
)
...
...
@@ -68,18 +67,18 @@ def _plot(
logging
.
warning
(
f
"
Cannot plot column
'
{
var
}
'
, because it is not present in data.
"
)
if
not
tmp
:
return
varname
=
tmp
varname
s
=
tmp
plots
=
len
(
varname
)
plots
=
len
(
varname
s
)
if
plots
>
1
:
fig
,
axes
=
plt
.
subplots
(
plots
,
1
,
sharex
=
True
)
axes
[
0
].
set_title
(
title
)
for
i
,
v
in
enumerate
(
varname
):
_plotByQualtyFlag
(
data
,
v
,
flagger
,
flagmask
,
axes
[
i
],
plot_nans
)
for
i
,
v
in
enumerate
(
varname
s
):
_plotByQual
i
tyFlag
(
data
,
v
,
flagger
,
flagmask
,
axes
[
i
],
plot_nans
)
else
:
fig
,
ax
=
plt
.
subplots
()
plt
.
title
(
title
)
_plotByQualtyFlag
(
data
,
varname
.
pop
(),
flagger
,
flagmask
,
ax
,
plot_nans
)
_plotByQual
i
tyFlag
(
data
,
varname
s
.
pop
(),
flagger
,
flagmask
,
ax
,
plot_nans
)
# dummy plot for the label `missing` see plot_vline for more info
plt
.
plot
([],
[],
"
:
"
,
color
=
"
silver
"
,
label
=
"
missing data
"
)
...
...
@@ -91,7 +90,7 @@ def _plot(
plt
.
show
()
def
_plotByQualtyFlag
(
data
,
varname
,
flagger
,
flagmask
,
ax
,
plot_nans
):
def
_plotByQual
i
tyFlag
(
data
,
varname
,
flagger
,
flagmask
,
ax
,
plot_nans
):
ax
.
set_ylabel
(
varname
)
x
=
data
.
index
...
...
@@ -106,7 +105,7 @@ def _plotByQualtyFlag(data, varname, flagger, flagmask, ax, plot_nans):
oldflags
=
flagged
&
~
flagmask
ax
.
plot
(
x
[
oldflags
],
y
[
oldflags
],
"
.
"
,
color
=
"
black
"
,
label
=
"
flagged by other test
"
)
if
plot_nans
:
_plot
_n
ans
(
y
[
oldflags
],
'
black
'
,
ax
)
_plot
N
ans
(
y
[
oldflags
],
'
black
'
,
ax
)
# now we just want to show data that was flagged
if
flagmask
is
not
True
:
...
...
@@ -117,29 +116,26 @@ def _plotByQualtyFlag(data, varname, flagger, flagmask, ax, plot_nans):
if
x
.
empty
:
return
suspicious
=
pd
.
Series
(
data
=
np
.
ones
(
len
(
y
),
dtype
=
bool
),
index
=
y
.
index
)
# flag by categories
# plot UNFLAGGED (only nans are needed)
flag
,
color
=
flagger
.
UNFLAGGED
,
_colors
[
'
unflagged
'
]
flagged
=
flagger
.
isFlagged
(
varname
,
flag
=
flag
,
comparator
=
'
==
'
)
ax
.
plot
(
x
[
flagged
],
y
[
flagged
],
'
.
'
,
color
=
color
,
label
=
f
"
flag:
{
flag
}
"
)
if
plot_nans
:
_plot
_n
ans
(
y
[
flagged
],
color
,
ax
)
_plot
N
ans
(
y
[
flagged
],
color
,
ax
)
# plot GOOD
flag
,
color
=
flagger
.
GOOD
,
_colors
[
'
good
'
]
flagged
=
flagger
.
isFlagged
(
varname
,
flag
=
flag
,
comparator
=
'
==
'
)
ax
.
plot
(
x
[
flagged
],
y
[
flagged
],
'
.
'
,
color
=
color
,
label
=
f
"
flag:
{
flag
}
"
)
if
plot_nans
:
_plot
_n
ans
(
y
[
flagged
],
color
,
ax
)
_plot
N
ans
(
y
[
flagged
],
color
,
ax
)
# plot BAD
flag
,
color
=
flagger
.
BAD
,
_colors
[
'
bad
'
]
flagged
=
flagger
.
isFlagged
(
varname
,
flag
=
flag
,
comparator
=
'
==
'
)
ax
.
plot
(
x
[
flagged
],
y
[
flagged
],
'
.
'
,
color
=
color
,
label
=
f
"
flag:
{
flag
}
"
)
if
plot_nans
:
_plot
_n
ans
(
y
[
flagged
],
color
,
ax
)
_plot
N
ans
(
y
[
flagged
],
color
,
ax
)
# plot SUSPICIOS
color
=
_colors
[
'
suspicious
'
]
...
...
@@ -147,18 +143,17 @@ def _plotByQualtyFlag(data, varname, flagger, flagmask, ax, plot_nans):
flagged
&=
flagger
.
isFlagged
(
varname
,
flag
=
flagger
.
BAD
,
comparator
=
'
<
'
)
ax
.
plot
(
x
[
flagged
],
y
[
flagged
],
'
.
'
,
color
=
color
,
label
=
f
"
{
flagger
.
GOOD
}
< flag <
{
flagger
.
BAD
}
"
)
if
plot_nans
:
_plot
_n
ans
(
y
[
flagged
],
color
,
ax
)
_plot
N
ans
(
y
[
flagged
],
color
,
ax
)
def
_plot
_n
ans
(
y
,
color
,
ax
):
def
_plot
N
ans
(
y
,
color
,
ax
):
nans
=
y
.
isna
()
_plotVline
(
ax
,
y
[
nans
].
index
,
color
=
color
)
def
_plotVline
(
plt
,
points
,
color
=
"
blue
"
):
def
_plotVline
(
ax
,
points
,
color
=
"
blue
"
):
# workaround for ax.vlines() as this work unexpected
# normally this should work like so:
# ax.vlines(idx, *ylim, linestyles=':', color='silver', label="missing")
for
point
in
points
:
plt
.
axvline
(
point
,
color
=
color
,
linestyle
=
"
:
"
)
ax
.
axvline
(
point
,
color
=
color
,
linestyle
=
"
:
"
)
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