Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Up MVP Package For Label-Image Creation #5

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ac43f60
change repo to package; begin Label class
AFg6K7h4fhy2 Oct 19, 2024
0d61506
update pyproject; minor additions to label.py; notes on labels
AFg6K7h4fhy2 Oct 24, 2024
2314b3b
more notes on possible utilities; more code on labels
AFg6K7h4fhy2 Oct 24, 2024
b522cb1
label templates without attrs
AFg6K7h4fhy2 Oct 24, 2024
62e807f
make use of attrs; add sensible and example defaults, remove some later
AFg6K7h4fhy2 Oct 24, 2024
47473a8
remove testing defaults
AFg6K7h4fhy2 Oct 25, 2024
7cfa496
minor, uncoordinated edits to Label classes
AFg6K7h4fhy2 Oct 29, 2024
c597aa1
develop docstrings
AFg6K7h4fhy2 Oct 29, 2024
9ea8d68
incremental progress on label creation
AFg6K7h4fhy2 Nov 2, 2024
166c422
more collections parameter options
AFg6K7h4fhy2 Nov 2, 2024
2bd5544
refine changes to collections label
AFg6K7h4fhy2 Nov 2, 2024
1e28b55
further systematics developments
AFg6K7h4fhy2 Nov 3, 2024
d8070e0
PIL experimentation file edits
AFg6K7h4fhy2 Nov 3, 2024
4ca1ba3
some attempts at ordering collections args
AFg6K7h4fhy2 Nov 3, 2024
2327a1c
try using attrs metadata
AFg6K7h4fhy2 Nov 3, 2024
1166153
add changes before kwargs edit
AFg6K7h4fhy2 Nov 3, 2024
f9cfe3a
attempts with dictionary of title values
AFg6K7h4fhy2 Nov 3, 2024
6092b90
getting closer with the label being ordered by parameters with use of…
AFg6K7h4fhy2 Nov 3, 2024
8485e33
some minor changes to close the night
AFg6K7h4fhy2 Nov 3, 2024
ff51c8b
update license from MIT to Apache2.0; update pyproject to reflect
AFg6K7h4fhy2 Nov 6, 2024
80a411b
update pre-commit config file
AFg6K7h4fhy2 Nov 6, 2024
182402a
fix pre-commit; update pre-commit workflow; create new file for exper…
AFg6K7h4fhy2 Nov 6, 2024
7405564
some attrs class examples
AFg6K7h4fhy2 Nov 6, 2024
f704db2
unfinished example C
AFg6K7h4fhy2 Nov 6, 2024
9d10ee7
intermediate point of attrs-ifying Label class
AFg6K7h4fhy2 Nov 6, 2024
bf2fce4
further progress
AFg6K7h4fhy2 Nov 6, 2024
75c92ee
collect docstrings in paste bin; update some of the Label params
AFg6K7h4fhy2 Nov 6, 2024
6851425
cover most parameters for Label
AFg6K7h4fhy2 Nov 6, 2024
23d106a
some code for instantiating dimensions
AFg6K7h4fhy2 Nov 6, 2024
19a1b05
label updates
AFg6K7h4fhy2 Nov 13, 2024
7ebeb61
attempt solving adding border
AFg6K7h4fhy2 Nov 13, 2024
7fafe81
absolute imports
AFg6K7h4fhy2 Nov 14, 2024
6cf774b
move out systematics
AFg6K7h4fhy2 Jan 12, 2025
4ca2509
Merge remote-tracking branch 'origin/main' into 2-set-up-mvp-package-…
AFg6K7h4fhy2 Jan 12, 2025
79fe6ef
example label usage
AFg6K7h4fhy2 Jan 12, 2025
2c6a116
pre-commit re-formatting
AFg6K7h4fhy2 Jan 12, 2025
50e1368
copyable text items
AFg6K7h4fhy2 Jan 12, 2025
e748350
mpl label testing
AFg6K7h4fhy2 Jan 12, 2025
cb3bab7
further mpl label making
AFg6K7h4fhy2 Jan 12, 2025
d87ab47
attempt with adding images to figures
AFg6K7h4fhy2 Jan 12, 2025
fd4b500
update label class with section creation
AFg6K7h4fhy2 Jan 12, 2025
0d3fa75
more label experimentation
AFg6K7h4fhy2 Jan 12, 2025
0211b7c
setup for further experimentation
AFg6K7h4fhy2 Jan 12, 2025
3dfb422
fix pre-commit
AFg6K7h4fhy2 Jan 12, 2025
c18bf3e
try precise text placement
AFg6K7h4fhy2 Jan 12, 2025
7f1538b
try latex based label
AFg6K7h4fhy2 Jan 27, 2025
a0b4b67
more label with latex attempts
AFg6K7h4fhy2 Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mpl label testing
AFg6K7h4fhy2 committed Jan 12, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit e748350e47132a9c54372a814ea40db2431bc939
Binary file added notebooks/label_with_text_boxes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions notebooks/mpl_text_plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# %%

import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

# %%

# label dimensions in inches
label_dimensions = (6, 4) # width, height

# create the label body
fig, ax = plt.subplots(figsize=label_dimensions)
ax.set_xlim(0, label_dimensions[0])
ax.set_ylim(0, label_dimensions[1])
ax.set_aspect("equal")
ax.axis("off")

# add background color
ax.add_patch(Rectangle((0, 0), *label_dimensions, color="lightblue"))

# add border
border_size = 0.1 # in inches
border_padding = 0.2 # in inches
left = border_padding
bottom = border_padding
right = label_dimensions[0] - border_padding
top = label_dimensions[1] - border_padding

ax.add_patch(
Rectangle(
(left, bottom),
right - left,
top - bottom,
edgecolor="black",
facecolor="none",
linewidth=border_size * 72,
)
) # Convert inches to points

# add text boxes
texts = [
{"text": "First Text Box", "font": "Arial", "size": 16, "style": "normal"},
{
"text": "Second Text Box",
"font": "Times New Roman",
"size": 14,
"style": "italic",
},
{
"text": "Third Text Box (SMALL CAPS)",
"font": "Courier New",
"size": 12,
"style": "small-caps",
},
]

# calculate vertical positions for the text boxes
box_height = (top - bottom) / len(texts)
for i, t in enumerate(texts):
text_x = label_dimensions[0] / 2 # centered horizontally
text_y = top - (i + 0.5) * box_height # stagger vertically

# adjust small caps style
if t["style"] == "small-caps":
t["text"] = t["text"].upper()

# load font properties
font_path = fm.findfont(fm.FontProperties(family=t["font"]))
font = fm.FontProperties(fname=font_path, size=t["size"])

# add text box
ax.text(
text_x,
text_y,
t["text"],
ha="center",
va="center",
fontproperties=font,
bbox=dict(
boxstyle="round,pad=0.5", facecolor="white", edgecolor="black"
),
)

# save or display the figure
plt.savefig("label_with_text_boxes.png", dpi=300)
plt.show()