How to use the pygmt.helpers.launch_external_viewer function in pygmt

To help you get started, we’ve selected a few pygmt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GenericMappingTools / pygmt / pygmt / figure.py View on Github external
Returns
        -------
        img : IPython.display.Image
            Only if ``method != 'external'``.

        """
        # Module level variable to know which figures had their show method
        # called. Needed for the sphinx-gallery scraper.
        SHOWED_FIGURES.append(self)

        if method not in ["static", "external"]:
            raise GMTInvalidInput("Invalid show method '{}'.".format(method))
        if method == "external":
            pdf = self._preview(fmt="pdf", dpi=dpi, anti_alias=False, as_bytes=False)
            launch_external_viewer(pdf)
            img = None
        elif method == "static":
            png = self._preview(
                fmt="png", dpi=dpi, anti_alias=True, as_bytes=True, transparent=True
            )
            if Image is None:
                raise GMTError(
                    " ".join(
                        [
                            "Cannot find IPython.",
                            "Make sure you have it installed",
                            "or use 'external=True' to open in an external viewer.",
                        ]
                    )
                )
            img = Image(data=png, width=width)
github GenericMappingTools / pygmt / pygmt / figure.py View on Github external
fmt = fmts[ext]
        if transparent:
            if fmt != "g":
                raise GMTInvalidInput(
                    "Transparency unavailable for '{}', only for png.".format(ext)
                )
            fmt = fmt.upper()
        if anti_alias:
            kwargs["Qt"] = 2
            kwargs["Qg"] = 2
        if ext == "kml":
            kwargs["W"] = "+k"

        self.psconvert(prefix=prefix, fmt=fmt, crop=crop, **kwargs)
        if show:
            launch_external_viewer(fname)