Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
p1
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Lenard Frank Weigel
p1
Commits
a5ffabd0
Commit
a5ffabd0
authored
1 year ago
by
Roger Wolf
Browse files
Options
Downloads
Patches
Plain Diff
add a small tool to allow for adding figures directly into Jupyter-notebook
parent
410b2abe
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/add_figure.py
+41
-0
41 additions, 0 deletions
tools/add_figure.py
with
41 additions
and
0 deletions
tools/add_figure.py
0 → 100755
+
41
−
0
View file @
a5ffabd0
#!/usr/bin/python3
from
os
import
getcwd
import
matplotlib.pyplot
as
plt
import
matplotlib.image
as
mpimg
def
add_figure
(
RELPATH
,
WIDTH
=
10.0
,
HEIGHT
=
10.0
):
"""
Display figure located at RELPATH through matplotlib rendering machine.
WIDTH and HEIGHT can be given as parameters of type float to determine the
measures of the figure. Nominally both are given in inches. Axes will be
suppressed.
"""
PREFIX
=
getcwd
()
+
"
/
"
print
(
PREFIX
+
RELPATH
)
print
(
RELPATH
[:
RELPATH
.
rfind
(
"
.
"
)].
replace
(
"
/
"
,
"
_
"
))
img
=
plt
.
figure
(
RELPATH
[:
RELPATH
.
rfind
(
"
.
"
)].
replace
(
"
/
"
,
"
_
"
),
figsize
=
(
WIDTH
,
HEIGHT
))
img
=
mpimg
.
imread
(
PREFIX
+
RELPATH
)
# Render image in background
imgplot
=
plt
.
imshow
(
img
)
# Hide axes
imgplot
.
axes
.
get_xaxis
().
set_visible
(
False
)
imgplot
.
axes
.
get_yaxis
().
set_visible
(
False
)
# Show image
plt
.
show
()
import
argparse
parser
=
argparse
.
ArgumentParser
(
prog
=
"
PROG
"
,
description
=
"
Add figure to code cell in Jupyter-notebook.
"
)
parser
.
add_argument
(
'
filename
'
,
type
=
str
,
nargs
=
1
,
help
=
'
Filename with relative path statement.
'
)
parser
.
add_argument
(
'
--witdh
'
,
type
=
float
,
dest
=
'
WIDTH
'
,
nargs
=
1
,
default
=
10.0
,
help
=
'
Width of file (default 10.0 inches).
'
)
parser
.
add_argument
(
'
--height
'
,
type
=
float
,
dest
=
'
HEIGHT
'
,
nargs
=
1
,
default
=
10.0
,
help
=
'
Height of file (default 10.0 inches).
'
)
args
=
parser
.
parse_args
()
add_figure
(
args
.
filename
[
0
],
args
.
WIDTH
,
args
.
HEIGHT
)
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