Jupyter 常见可视化框架的选择_光环大数据培训
光环大数据光环大数据-大数据培训大数据培训 sns.set(color_codes=True)iris = sns.load_dataset(“iris“)species = iris.pop(“species“)g = sns.clustermap(iris)光环大数据光环大数据-大数据培训大数据培训&人工智能培训人工智能培训http:/hadoop.aura.cn 光环大数据光环大数据 http:/hadoop.aura.cnplotlyplotly 是跨平台 JavaScript 交互式绘图包,由于开发者的核心是javascript,所以整个语法类似于写 json 配置,语法特质也介于陈述式和命令式之间,无服务版本是免费的。有点是学习成本不高,可以很快将语句移植到 javascript 版本;缺点是语言相对繁琐。#plotly 示例 import plotly.plotly as pyimport plotly.graph_objs as go # Add datamonth = 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'high_2000 = 32.5, 37.6, 49.9, 53.0, 69.1, 75.4, 76.5, 76.6, 70.7, 60.6, 45.1, 29.3low_2000 = 13.8, 22.3, 32.5, 37.2, 49.9, 56.1, 57.7, 58.3, 51.2, 42.8, 31.6, 15.9high_2007 = 36.5, 26.6, 43.6, 52.3, 71.5, 81.4, 80.5, 82.2, 76.0, 67.3, 46.1, 35.0low_2007 = 23.6, 14.0, 27.0, 36.8, 47.6, 57.7, 58.9, 61.2, 53.3, 48.5, 31.0, 23.6high_2014 = 28.8, 28.5, 37.0, 56.8, 69.7, 79.7, 78.5, 77.8, 74.1, 62.6, 45.3, 39.9low_2014 = 12.7, 14.3, 18.6, 35.5, 49.9, 58.0, 60.0, 58.6, 51.7, 45.2, 32.2, 29.1 # Create and style tracestrace0 = go.Scatter( x = month, y = high_2014, name = 'High 2014', line = dict( color = ('rgb(205, 12, 24)'), width = 4)trace1 = go.Scatter( x = month, y = low_2014, name = 'Low 2014', line = dict( color = ('rgb(22, 96, 167)'), width = 4,)trace2 = go.Scatter( x = month, y = high_2007, name = 'High 2007', line = dict( color = ('rgb(205, 12, 24)'), width = 4, dash = 'dash') # dash options include 'dash', 'dot', and 'dashdot')trace3 = go.Scatter( x = month, y = low_2007, name = 'Low 2007', line = dict( color = ('rgb(22, 96, 167)'), width = 4, dash = 'dash')trace4 = go.Scatter( x = month, y = high_2000, name = 'High 2000', line = dict( color = ('rgb(205, 12, 24)'), 光环大数据光环大数据-大数据培训大数据培训&人工智能培训人工智能培训http:/hadoop.aura.cn 光环大数据光环大数据 http:/hadoop.aura.cnwidth = 4, dash = 'dot')trace5 = go.Scatter( x = month, y = low_2000, name = 'Low 2000', line = dict( color = ('rgb(22, 96, 167)'), width = 4, dash = 'dot')data = trace0, trace1, trace2, trace3, trace4, trace5 # Edit the layoutlayout = dict(title = 'Average High and Low Temperatures in New York', xaxis = dict(title = 'Month'), yaxis = dict(title = 'Temperature (degrees F)'), ) fig = dict(data=data, layout=layout)py.iplot(fig, filename='styled-line')注意:此框架在 jupyter 中使用需要使用 init_notebook_mode()加载JavaScript 框架。bokehbokeh 是 pydata 维护的比较具有潜力的开源交互可视化框架。值得一说的是,该框架同时提供底层语句和陈述式绘图命令。相对来说语法也比较清楚,但其配置语句依旧有很多可视化框架的问题,就是与陈述式命令不符,没有合理的结构。此外,一些常见的交互效果都是以底层命令的方式使用的,因此如果要快速实现 Dashboard 或者作图时就显得较为不便了。# Bokeh 示例 import numpy as npimport scipy.special from bokeh.layouts import gridplotfrom bokeh.plotting import figure, show, output_file p1 = figure(title=“Normal Distribution (=0, =0.5)“,tools=“save“, background_fill_color=“#E8DDCB“) mu, sigma = 0, 0.5 measured = np.random.normal(mu, sigma, 1000)hist, edges = np.histogram(measured, density=True, bins=50) x = np.linspace(-2, 2, 1000)pdf = 1/(sigma * np.sqrt(2*np.pi) * np.exp(-(x-mu)*2 / (2*sigma*2)cdf = (1+scipy.special.erf(x-光环大数据光环大数据-大数据培训大数据培训&人工智能培训人工智能培训http:/hadoop.aura.cn 光环大数据光环大数据 http:/hadoop.aura.cnmu)/np.sqrt(2*sigma*2)/2 p1.quad(top=hist, bottom=0, left=edges:-1, right=edges1:, fill_color=“#036564“, line_color=“#033649“)p1.line(x, pdf, line_color=“#D95B43“, line_width=8, alpha=0.7, legend=“PDF“)p1.line(x, cdf, line_color=“white“, line_width=2, alpha=0.7, legend=“CDF“) p1.legend.location = “center_right“p1.legend.background_fill_color = “darkgrey“p1.xaxis.axis_label = 'x'p1.yaxis.axis_label = 'Pr(x)' p2 = figure(title=“Log Normal Distribution (=0, =0.5)“, tools=“save“, background_fill_color=“#E8DDCB“) mu, sigma = 0, 0.5 measured = np.random.lognormal(mu, sigma, 1000)hist, edges = np.histogram(measured, density=True, bins=50) x = np.linspace(0.0001, 8.0, 1000)pdf = 1/(x* sigma * np.sqrt(2*np.pi) * np.exp(-(np.log(x)-mu)*2 / (2*sigma*2)cdf = (1+scipy.special.erf(np.log(x)-mu)/(np.sqrt(2)*sigma)/2 p2.quad(top=hist, bottom=0, left=edges:-1, right=edges1:, fill_color=“#036564“, line_color=“#033649“)p2.line(x, pdf, line_color=“#D95B43“, line_width=8, alpha=0.7, legend=“PDF“)p2.line(x, cdf, line_color=“white“, line_width=2, alpha=0.7, legend=“CDF“) p2.legend.location = “center_right“p2.legend.background_fill_color = “darkgrey“p2.xaxis.axis_label = 'x'p2.yaxis.axis_label = 'Pr(x)' p3 = figure(title=“Gamma Distribution (k=1, =2)“, tools=“save“, background_fill_color=“#E8DDCB“) k, theta = 1.0, 2.0 measured = np.random.gamma(k, theta, 1000)hist, edges = np.histogram(measured, density=True, bins