Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subplots or multiple plots overlaid? #303

Open
will-hill opened this issue Aug 17, 2024 · 2 comments
Open

Subplots or multiple plots overlaid? #303

will-hill opened this issue Aug 17, 2024 · 2 comments

Comments

@will-hill
Copy link

Is it possible to have two plot geometries in a single Chart? I would like to plot a time series 'line' for forecasting and 'circle' for actual values. Is this possible?

@veghdev
Copy link
Member

veghdev commented Aug 22, 2024

Hi, it is not supported by default, but it can be solved with a little trickery, you have to create two separate charts and then place them on top of each other in javascript, see the example code below.

But the javascript solution could depend on the notebook type you are using, I tested it in a basic jupyter notebook.

import pandas as pd
from ipyvizzu import Chart, Data, Config, Style


df = pd.read_csv(
    "https://ipyvizzu.vizzuhq.com/0.17/assets/data/chart_types_eu.csv"
)
data = Data()
data.add_df(df)

chart1 = Chart()
chart1.animate(
    data, Config(
        {
            "channels": {
                "x": "Joy factors",
                "y": "Value 2 (+)"
            },
            "title": "Multi layer chart"
        }
    )
)

chart2 = Chart()
chart2.animate(
    data, Config(
        {
            "channels": {
                "x": {
                    "set": "Joy factors",
                    "markerGuides": True,
                    "labels": False,
                    "axis": False
                },
                "y": {
                    "set": "Value 1 (+)",
                    "interlacing": False,
                    "title": None
                },
            },
            "label": "Value 1 (+)",
            "geometry": "line",
            "title": ' '
        }
    ),
    Style(
        {
            "backgroundColor": "#ffffff00",
            "plot": {
                "marker": {
                    "colorPalette": "#FFA000"
                }
            }
        }
    )
)

reposition = f"""
let container1 = window.ipyvizzu.elements['{chart1._chart_id}']
let container2 = window.ipyvizzu.elements['{chart2._chart_id}']
container2.style = `
            width: ${{container1.width}}px; 
            height: ${{container1.height}}px; 
            position: absolute; 
            top: ${{container1.offsetTop}}px; 
            left: ${{container1.offsetLeft}}px;
`
container1.parentElement.appendChild(container2)
"""
chart2._display(reposition)

@veghdev
Copy link
Member

veghdev commented Aug 22, 2024

If it works well, you should see the charts below
Screenshot from 2024-08-22 17-24-41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants