用Python绘制Highcharts图
我正在使用一个名为 justpy 的新 Python Web 框架,它允许您仅使用 Python 构建 Web 应用程序的后端和前端。该框架还与 javascript Highcharts 库集成。以下是构建包含 Highcharts 图的 Web 应用程序的方法:
import justpy as jp
import pandas as pd
wm = pd.read_csv('https://elimintz.github.io/women_majors.csv').round(2)
# Create list of majors which start under 20% women students
wm_under_20 = list(wm.loc[0, wm.loc[0] < 20].index)
def women_majors():
wp = jp.WebPage()
wm.jp.plot(0, wm_under_20, kind='spline', a=wp, title='The gender gap is transitory - even for extreme cases',
subtitle='Percentage of Bachelors conferred to women form 1970 to 2011 in the US for extreme cases where the percentage was less than 20% in 1970',
classes='m-2 p-2 w-3/4')
return wp
jp.justpy(women_majors)
这将在 localhost:8000 上加载 webapp:
我现在想弄清楚如何只显示 Highcharts 图,而不必构建 Web 应用程序。
如果我将上面的代码修改为:
import justpy as jp
import pandas as pd
wm = pd.read_csv('https://elimintz.github.io/women_majors.csv').round(2)
# Create list of majors which start under 20% women students
wm_under_20 = list(wm.loc[0, wm.loc[0] < 20].index)
fig = wm.jp.plot(0, wm_under_20, kind='spline', title='The gender gap is transitory - even for extreme cases',
subtitle='Percentage of Bachelors conferred to women form 1970 to 2011 in the US for extreme cases where the percentage was less than 20% in 1970',
classes='m-2 p-2 w-3/4')
print(fig)
这将返回以下输出:
HighCharts(id: 1, vue_type: chart, chart options: {'series': [{'data': [4.23,...
如何使用 HighCharts 对象制作图像文件(或在 Jupyter 笔记本中显示绘图)而无需构建 Web 应用程序?