Last active
December 30, 2020 04:58
-
-
Save dridk/b8d3a69924643336c3344d2cb7e3333c to your computer and use it in GitHub Desktop.
pip install PySide2 altair vega_datasets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pip install PySide2 altair vega_datasets