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

Adjust figsize #20

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
# We can also give a solution width (and/or height) limit
solution = rps.Solver().solve(problem=problem, height_limit=6.5)
print("solution (with limit):", solution)
rps.Visualizer().visualize(solution=solution, path="./figs/floorplan_limit.png")
rps.Visualizer().visualize(solution=solution, path="./figs/floorplan_example_limit.png")


if __name__ == "__main__":
Expand Down
Binary file modified figs/floorplan_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/floorplan_example_limit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/floorplan_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/floorplan_large_limit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed figs/floorplan_limit.png
Binary file not shown.
12 changes: 7 additions & 5 deletions rectangle_packing_solver/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ def visualize(self, solution: Solution, path: str = "floorplan.png", title: str
bounding_box = solution.floorplan.bounding_box

# Figure settings
fig = plt.figure(figsize=(10, 10))
bb_width = bounding_box[0]
bb_height = bounding_box[1]
fig = plt.figure(figsize=(10, 10 * bb_height / bb_width + 0.5))
ax = plt.axes()
ax.set_aspect("equal")
plt.xlim([0, bounding_box[0]])
plt.ylim([0, bounding_box[1]])
plt.xlim([0, bb_width])
plt.ylim([0, bb_height])
plt.xlabel("X")
plt.ylabel("Y")
plt.title(title)
Expand All @@ -62,8 +64,8 @@ def visualize(self, solution: Solution, path: str = "floorplan.png", title: str

# Add text label
centering_offset = 0.011
center_x = rectangle["x"] + rectangle["width"] / 2 - bounding_box[0] * centering_offset
center_y = rectangle["y"] + rectangle["height"] / 2 - bounding_box[1] * centering_offset
center_x = rectangle["x"] + rectangle["width"] / 2 - bb_width * centering_offset
center_y = rectangle["y"] + rectangle["height"] / 2 - bb_height * centering_offset
ax.text(x=center_x, y=center_y, s=rectangle["id"], fontsize=18, color=fontcolor)

# Output
Expand Down