python - 如何在 cmd 中运行此代码以查看可视化输出?
问题描述
我已经在 jupyter notebook 中运行了这段代码,并成功获得了交互式散点图输出。但是我想从 cmd 运行这个特定的代码,所以我继续将它保存为 .py 文件并通过 cmd 运行它,我没有收到任何错误但我没有看到可视化,有人可以帮我吗
import plotly.graph_objs as go
import plotly.offline as py
import pandas as pd
import numpy as np
from ipywidgets import interactive, HBox, VBox
py.init_notebook_mode()
df = pd.read_csv('https://raw.githubusercontent.com/jonmmease/plotly_ipywidget_notebooks/master/notebooks/data/cars/cars.csv')
f = go.FigureWidget([go.Scatter(y = df['City mpg'], x = df['City mpg'], mode = 'markers')])
scatter = f.data[0]
N = len(df)
scatter.x = scatter.x + np.random.rand(N)/10 *(df['City mpg'].max() - df['City mpg'].min())
scatter.y = scatter.y + np.random.rand(N)/10 *(df['City mpg'].max() - df['City mpg'].min())
scatter.marker.opacity = 0.5
def update_axes(xaxis, yaxis):
scatter = f.data[0]
scatter.x = df[xaxis]
scatter.y = df[yaxis]
with f.batch_update():
f.layout.xaxis.title = xaxis
f.layout.yaxis.title = yaxis
scatter.x = scatter.x + np.random.rand(N)/10 *(df[xaxis].max() - df[xaxis].min())
scatter.y = scatter.y + np.random.rand(N)/10 *(df[yaxis].max() - df[yaxis].min())
axis_dropdowns = interactive(update_axes, yaxis = df.select_dtypes('int64').columns, xaxis = df.select_dtypes('int64').columns)
# Create a table FigureWidget that updates on selection from points in the scatter plot of f
t = go.FigureWidget([go.Table(
header=dict(values=['City mpg','Classification','Driveline','Engine Type','Fuel Type','Height','Highway mpg','Horsepower','Hybrid','ID','Length','Make','Model Year','Number of Forward Gears','Torque','Transmission','Width','Year'],
fill = dict(color='#C2D4FF'),
align = ['left'] * 5),
cells=dict(values=[df[col] for col in ['City mpg','Classification','Driveline','Engine Type','Fuel Type','Height','Highway mpg','Horsepower','Hybrid','ID','Length','Make','Model Year','Number of Forward Gears','Torque','Transmission','Width','Year']],
fill = dict(color='#F5F8FF'),
align = ['left'] * 5))])
def selection_fn(trace,points,selector):
t.data[0].cells.values = [df.loc[points.point_inds][col] for col in ['City mpg','Classification','Driveline','Engine Type','Fuel Type','Height','Highway mpg','Horsepower','Hybrid','ID','Length','Make','Model Year','Number of Forward Gears','Torque','Transmission','Width','Year']]
scatter.on_selection(selection_fn)
# Put everything together
VBox((HBox(axis_dropdowns.children),f,t))
'''
The expected result should be an html page with the visualization as the output ran from cmd
解决方案
在 cmd 上转到 .py 文件所在的目录并键入python yourfilename.py
或python3 yourfilename.py
推荐阅读
- html - 在 HTML 中没有类的情况下水平对齐文章和放在一边
- c# - 使用约束和暂停支持作用于每个 DynamicData SourceCache 项
- python - 如何将元组元素原始数据插入 SQL 表?
- python-3.x - 从其他 python 文件夹导入模块
- javascript - 我如何在 discord.js 中每 10 秒编辑一次嵌入
- plotly-dash - 如何使用 Dash 在数据表的单元格中创建链接(url)
- awk - 使用 awk 进行系统调用
- python - 如何正确地将代理轮换器添加到脚本中?
- python - multiprocessing.pool() 无限期挂起
- c# - 在现有的 chrome 浏览器上运行 selenium?