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

Export image #11

Merged
merged 20 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
18 changes: 18 additions & 0 deletions dimes/dimensional_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,27 @@ def finalize_plot(self):

def write_html_plot(self, path: Path) -> None:
"Write plots to html file at specified path."
self.figure.layout["width"] = None
self.figure.layout["height"] = None
self.finalize_plot()
self.figure.write_html(path)

def write_image_plot(
self, path: Path, width: int | None = None, height: int | None = None, scale: int | float | None = None
) -> None:
"""
Write plots to html file at specified path.
scale (int, float, None): Adjusts the resolution of the output image.
A value cannot be equal to or less than 0 or greater than 16.
"""
if scale is not None:
if (scale > 16) | (scale <= 0):
raise ValueError(f"Scale value {scale} cannot be greater than 16 or less than or equal to 0.")
self.figure.layout["width"] = width
self.figure.layout["height"] = height
self.finalize_plot()
self.figure.write_image(path, scale=scale)


def get_subplot_domains(number_of_subplots: int, gap: float = 0.05) -> list[tuple[float, float]]:
"""Calculate and return the 'Y' domain ranges for a given number of subplots with the specified gap size."""
Expand Down
19 changes: 17 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a formatter was automatically applied to this file, causing unrelated diffs. Not sure I like it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want to do about it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change your editor settings so it doesn't automatically format TOML files (or at least disable the reordering of keywords).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find the setting. I will need your help.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = "https://github.com/bigladder/dimes"
python = "^3.10"
plotly = "*"
koozie = "^1.3.0"
kaleido = "==0.2.1" # Required by plotly to save figures as images

[tool.poetry.dev-dependencies]
pytest = "^7.1.3"
Expand Down
Loading