Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a plotly function to build a histogram:

def Histogram(file_path, rows, columns):
    df = file_reading(file_path, rows)
    column1 = columns[0]
    fig = px.histogram(df, x=column1).update_xaxes(
        categoryorder='total ascending')
    Plotly_json = fig.to_json()
    return Plotly_json


It needs to be returned in Json format.

This is a sample of what the Json version of the plot looks like:

{
    "path": {
        "data": [
            {
                "alignmentgroup": "True",
                "bingroup": "x",
                "hovertemplate": "age=%{x}<br>count=%{y}<extra></extra>",
                "legendgroup": "",
                "marker": {
                    "color": "#636efa",
                    "pattern": {
                        "shape": ""
                    }
                },
                "name": "",
                "offsetgroup": "",
                "orientation": "v",
                "showlegend": false,
                "x": [
                    "48",
                    "7",
                    "62",
                    "48",
                    "51",
                    "60",
                    "68",
                    "24"
                ],
                "xaxis": "x",
                "yaxis": "y",
                "type": "histogram"
            }
        ],
        "layout": {
            "template": {
                "data": {
                    "histogram2dcontour": [
                        {
                            "type": "histogram2dcontour",
                            "colorbar": {
                                "outlinewidth": 0,
                                "ticks": ""
                            },...................


What I have tried:

I want a similar Json format for the following 'Lux Visualization' code:

def lux_vis(eda_file, vis_file_path_intent, intent_list):
    
    # Visualizing selected variables
    eda_file.intent = intent_list
    eda_file.save_as_html(vis_file_path_intent)



But the to_json() method doesn't work for the Lux library. Is there an alternative to it?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900