Skip to content

Instantly share code, notes, and snippets.

@dridk
Last active December 30, 2020 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dridk/b8d3a69924643336c3344d2cb7e3333c to your computer and use it in GitHub Desktop.
Save dridk/b8d3a69924643336c3344d2cb7e3333c to your computer and use it in GitHub Desktop.
pip install PySide2 altair vega_datasets
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings
import sys
import altair as alt
import pandas as pd
from vega_datasets import data
class VegaWidget(QWebEngineView):
"""docstring for ClassName"""
def __init__(self, parent=None):
super().__init__(parent)
def plot(self):
source = data.cars()
chart = (
alt.Chart(source)
.mark_circle(size=60)
.encode(
x="Horsepower",
y="Miles_per_Gallon",
color="Origin",
tooltip=["Name", "Origin", "Horsepower", "Miles_per_Gallon"],
)
.properties(width=self.width() - 100, height=self.height() - 100)
.interactive()
)
self.setHtml(chart.to_html())
if __name__ == "__main__":
app = QApplication(sys.argv)
w = VegaWidget()
w.plot()
w.show()
app.exec_()
@dridk
Copy link
Author

dridk commented Dec 29, 2020

pip install PySide2 altair vega_datasets

@dridk
Copy link
Author

dridk commented Dec 29, 2020

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment