Skip to content

Commit

Permalink
Merge pull request #11 from bigladder/export-image
Browse files Browse the repository at this point in the history
Export image
  • Loading branch information
nealkruis authored Feb 3, 2025
2 parents 4da9d01 + 0e9221a commit c0970f8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
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
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

0 comments on commit c0970f8

Please sign in to comment.