Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RSE 23 Group Assignment Shervud Pitawanik Franz
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Niklas Franz
RSE 23 Group Assignment Shervud Pitawanik Franz
Commits
6d8f9941
Commit
6d8f9941
authored
1 year ago
by
niklasfranz
Browse files
Options
Downloads
Patches
Plain Diff
feat: introduced flexible x_ticks for boxplots
parent
84e4930e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!22
Resolve "flexible x-label-tick-counts for boxplots"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plotter.py
+55
-1
55 additions, 1 deletion
src/Plotter.py
with
55 additions
and
1 deletion
src/Plotter.py
+
55
−
1
View file @
6d8f9941
...
...
@@ -198,7 +198,10 @@ class Plotter:
)
def
plot_categorical_boxplot
(
self
,
target
:
str
,
category
:
str
,
styling_params
:
dict
=
{}
self
,
target
:
str
,
category
:
str
,
styling_params
:
dict
=
{},
x_tick_count
:
int
=
None
,
x_tick_step
:
int
=
None
)
->
None
:
"""
plot a categorical boxplot.
...
...
@@ -206,6 +209,12 @@ class Plotter:
target (str, must be present as a column in the dataset),
category (str, must be present as a column in the dataset),
styling_params (dict)
x_tick_count: define the amount of x_ticks on the x axis.
cannot be used in combination with x_tick_step
should not be used with categorical values
x_tick_step: define the incremental steps of x_ticks values.
cannot be used in combination with x_tick_count
should not be used with categorical values
Returns:
...
...
@@ -249,6 +258,32 @@ class Plotter:
)
raise
ValueError
(
"
parameter styling params should be a dict.
"
)
if
(
type
(
x_tick_count
)
!=
int
)
and
(
x_tick_count
is
not
None
):
logging
.
error
(
"
Plotter.plot_categorical_boxplot(): parameter
\
x_tick_count should be an integer.
"
)
raise
ValueError
(
"
parameter styling params should be a dict.
"
)
if
(
type
(
x_tick_step
)
!=
int
)
and
(
x_tick_step
is
not
None
):
logging
.
error
(
"
Plotter.plot_categorical_boxplot(): parameter
\
x_tick_step should be an integer.
"
)
raise
ValueError
(
"
parameter styling x_tick_step should be an int.
"
)
if
x_tick_step
is
not
None
and
x_tick_count
is
not
None
:
logging
.
error
(
"
Plotter.plot_categorical_boxplot(): parameters
\
x_tick_step and x_tick_count cannot be used
\
simultaneously. Use either one or the other,
\
exclusively
"
)
raise
KeyError
(
"
Plotter.plot_categorical_boxplot(): parameters
\
x_tick_step and x_tick_count cannot be used
\
simultaneously. Use either one or the other,
\
exclusively
"
)
logging
.
debug
(
"
Plotter.plot_categorical_boxplot(): all params valid,
\
plotting plot_categorical_boxplot():
\n
\
...
...
@@ -262,6 +297,25 @@ class Plotter:
self
.
customize_plot
(
fig
,
ax
,
styling_params
)
sns
.
boxplot
(
x
=
category
,
y
=
target
,
data
=
self
.
df
,
palette
=
"
rainbow
"
)
if
x_tick_count
or
x_tick_step
:
x_limits
=
ax
.
get_xlim
()
upper_xlim
=
int
(
x_limits
[
1
])
lower_xlim
=
int
(
x_limits
[
0
])
if
x_tick_count
:
step
=
(
upper_xlim
-
lower_xlim
)
//
(
x_tick_count
-
1
)
x_ticks
=
[
int
(
lower_xlim
+
step
*
i
)
for
i
in
range
(
x_tick_count
)]
elif
x_tick_step
:
step
=
x_tick_step
current_tick
=
lower_xlim
x_ticks
=
[
current_tick
]
while
current_tick
+
step
<
upper_xlim
:
x_ticks
.
append
(
current_tick
+
step
)
current_tick
+=
step
print
(
x_ticks
)
plt
.
xticks
(
x_ticks
)
def
plot_categorical_histplot
(
self
,
target
:
str
,
...
...
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