diff --git a/dimes/dimensional_plot.py b/dimes/dimensional_plot.py index 0222f7d..e65ab1f 100644 --- a/dimes/dimensional_plot.py +++ b/dimes/dimensional_plot.py @@ -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.""" diff --git a/poetry.lock b/poetry.lock index 0adf3c2..7082bd1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "astroid" @@ -173,6 +173,21 @@ files = [ [package.extras] colors = ["colorama (>=0.4.6)"] +[[package]] +name = "kaleido" +version = "0.2.1" +description = "Static image export for web-based visualization libraries with zero dependencies" +optional = false +python-versions = "*" +files = [ + {file = "kaleido-0.2.1-py2.py3-none-macosx_10_11_x86_64.whl", hash = "sha256:ca6f73e7ff00aaebf2843f73f1d3bacde1930ef5041093fe76b83a15785049a7"}, + {file = "kaleido-0.2.1-py2.py3-none-macosx_11_0_arm64.whl", hash = "sha256:bb9a5d1f710357d5d432ee240ef6658a6d124c3e610935817b4b42da9c787c05"}, + {file = "kaleido-0.2.1-py2.py3-none-manylinux1_x86_64.whl", hash = "sha256:aa21cf1bf1c78f8fa50a9f7d45e1003c387bd3d6fe0a767cfbbf344b95bdc3a8"}, + {file = "kaleido-0.2.1-py2.py3-none-manylinux2014_aarch64.whl", hash = "sha256:845819844c8082c9469d9c17e42621fbf85c2b237ef8a86ec8a8527f98b6512a"}, + {file = "kaleido-0.2.1-py2.py3-none-win32.whl", hash = "sha256:ecc72635860be616c6b7161807a65c0dbd9b90c6437ac96965831e2e24066552"}, + {file = "kaleido-0.2.1-py2.py3-none-win_amd64.whl", hash = "sha256:4670985f28913c2d063c5734d125ecc28e40810141bdb0a46f15b76c1d45f23c"}, +] + [[package]] name = "koozie" version = "1.3.0" @@ -498,4 +513,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "a0c4e1d087dae51b0d98ddb13075bd77d317b193b0a185cbea6f30c7c3eacb9d" +content-hash = "7079ef6f7385f8e6e83f49172804cec963f0f36e57a5f1cbb0363c1f6546a1bd" diff --git a/pyproject.toml b/pyproject.toml index 9b7e2bc..e9f0aef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"