コード例 #1
0
def generate_graphs(n_intervals):
    """
    This callback generates three simple graphs from random data.
    """
    # simulate expensive graph generation process
    print("running")
    print("n_intervals: ", n_intervals)

    results_dict = {}

    for ctag in COMPRESSOR_TAGS:
        print(f"Loading {ctag}.")
        json_files = [str(f) for f in DATA_PATH.glob("*.json")]
        json_files = [f for f in json_files if ctag in f]
        json_files = sorted(json_files)

        eff_file = json_files[0]
        sample_datetime_raw = eff_file.split("time-")[-1]
        sample_date, sample_time = sample_datetime_raw.split("_")
        sample_time = sample_time.replace("-", ":").replace(".json", "")

        sample_datetime = sample_date + " " + sample_time

        results_dict[f"sample-time-{ctag}"] = sample_datetime

        for curve in ["head", "eff", "power"]:
            # Head
            file_path = DATA_PATH / f"{ctag}_{curve}_plot-time-{sample_datetime_raw}"
            fig = pio.read_json(str(file_path))
            results_dict[f"{curve}-{ctag}"] = fig

    # save figures in a dictionary for sending to the dcc.Store
    return results_dict
コード例 #2
0
def test_read_json_from_filelike(fig1, fig_type_spec, fig_type):
    # Configure file-like mock
    filemock = MagicMock()
    filemock.read.return_value = pio.to_json(fig1)

    # read_json on mock file
    fig1_loaded = pio.read_json(filemock, output_type=fig_type_spec)

    # Check return type
    assert isinstance(fig1_loaded, fig_type)

    # Check loaded figure
    assert pio.to_json(fig1_loaded) == pio.to_json(fig1.to_dict())
コード例 #3
0
def test_read_json_from_filelike(fig1, fig_type_spec, fig_type):
    # Configure file-like mock
    filemock = MagicMock()
    filemock.read.return_value = pio.to_json(fig1)

    # read_json on mock file
    fig1_loaded = pio.read_json(filemock, output_type=fig_type_spec)

    # Check return type
    assert isinstance(fig1_loaded, fig_type)

    # Check loaded figure
    assert pio.to_json(fig1_loaded) == pio.to_json(fig1.to_dict())
コード例 #4
0
ファイル: abxrxpro.py プロジェクト: CaileanCarter/AbxRxPro
    def open_profile(self, profile):
        logging.info(f"""{date.strftime("%d/%m/%Y %H:%M")}   Starting new log.
        
Opening profile: {profile}""")

        print(f"Loading {profile}...")

        fig = pio.read_json(rf"{self.relativepath}\profiles\{profile}.json"
                            )  # open main profile

        try:
            gffig = pio.read_json(
                rf"{self.relativepath}\profiles\{profile}_gf.json"
            )  # open gene frequency plot
        except FileNotFoundError:
            self.show_genefrequency = True
            logging.warning(
                "No gene frequency file associated with this profile. Possibly no genotypic data available."
            )

        logging.info("Profile associated files openned.")

        if self.export:
            self.export_HTML(profile, fig,
                             gffig)  # export the profile if user requested

        print(f"{profile} has loaded... \nNow plotting...")

        pio.show(fig)
        logging.info("Main plot displayed")

        if not self.show_genefrequency:
            pio.show(gffig)
            logging.info("Gene frequency plot displayed")
            logging.info("Done. \n \n")

        print(f"{profile} is now displaying...")
コード例 #5
0
def test_read_json_from_file_string(fig1, fig_type_spec, fig_type):
    with tempfile.TemporaryDirectory() as dir_name:

        # Write json file
        path = os.path.join(dir_name, "fig1.json")
        with open(path, "w") as f:
            f.write(pio.to_json(fig1))

        # read json from file as string
        fig1_loaded = pio.read_json(path, output_type=fig_type_spec)

        # Check return type
        assert isinstance(fig1_loaded, fig_type)

        # Check loaded figure
        assert pio.to_json(fig1_loaded) == pio.to_json(fig1.to_dict())
コード例 #6
0
def test_read_json_from_file_string(fig1, fig_type_spec, fig_type):
    with tempfile.TemporaryDirectory() as dir_name:

        # Write json file
        path = os.path.join(dir_name, 'fig1.json')
        with open(path, 'w') as f:
            f.write(pio.to_json(fig1))

        # read json from file as string
        fig1_loaded = pio.read_json(path, output_type=fig_type_spec)

        # Check return type
        assert isinstance(fig1_loaded, fig_type)

        # Check loaded figure
        assert pio.to_json(fig1_loaded) == pio.to_json(fig1.to_dict())
コード例 #7
0
ファイル: plotly.py プロジェクト: SimonBoothroyd/nonbonded
    def to_plotly(
        self,
        subplot_width: float = 350.0,
        subplot_height: float = 350.0,
        subplots_per_row: Optional[int] = None,
    ) -> "PlotlyFigure":
        """Converts the pydantic representation of a plotly figure to an actual
        plotly figure object.

        Parameters
        ----------
        subplot_width
            The width of each subplot.
        subplot_height
            The height of each subplot.
        subplots_per_row
            The maximum subplots per row. If none, all subplots will be drawn on a
            single row.

        Notes
        -----
        * This function is mainly available only for debug purposes.
        """
        from plotly.io import read_json

        # Build up the rest of the JSON dictionary.
        figure_dictionary = {
            "data": [{
                **trace.dict(), "xaxis": f"x{i + 1}",
                "yaxis": f"y{i + 1}"
            } for i, subplot in enumerate(self.subplots)
                     for trace in subplot.traces],
            "layout":
            self._generate_layout(subplot_width, subplot_height,
                                  subplots_per_row),
            "config": {
                "displayModeBar": False
            },
        }

        figure = read_json(StringIO(json.dumps(figure_dictionary)))
        return figure
コード例 #8
0
def html_exporter(file_path: str, new_file_path: str):
    plotly_fig = read_json(file_path)
    write_html(plotly_fig, new_file_path)
コード例 #9
0
 def _load(self) -> graph_objects.Figure:
     load_path = get_filepath_str(self._get_load_path(), self._protocol)
     return pio.read_json(load_path, **self._load_args)
コード例 #10
0
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.io as pio

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

plot_3d = pio.read_json('../plots/plot_3d.json')
plot_2d = pio.read_json('../plots/plot_2d.json')

app.layout = html.Div(children=[
    dcc.Markdown(children='''
        # Dash > Power BI
        Por que?
        
        * Gratis
        * Python
        * Flex
        
    '''),
    dcc.Graph(id="3d", figure=plot_3d),
    dcc.Graph(id="2d", figure=plot_2d),
])

if __name__ == '__main__':
    app.run_server(debug=True)