def boxplot_charts(): page = Page() chart_init = { "width": WIDTH, "height": HEIGHT, } chart = Boxplot("箱形图-单图例", **chart_init) x_axis = ['expr1', 'expr2', 'expr3', 'expr4', 'expr5'] y_axis = [[ 850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960 ], [ 960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800 ], [ 880, 880, 880, 860, 720, 720, 620, 860, 970, 950, 880, 910, 850, 870, 840, 840, 850, 840, 840, 840 ], [ 890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780 ], [ 890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870 ]] _yaxis = chart.prepare_data(y_axis) chart.add("boxplot", x_axis, _yaxis) page.add(chart) chart = Boxplot("箱形图-多图例", **chart_init) x_axis = ['expr1', 'expr2'] y_axis1 = [[ 850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960 ], [ 960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800 ]] y_axis2 = [[ 890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780 ], [ 890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870 ]] chart.add("category1", x_axis, chart.prepare_data(y_axis1)) chart.add("category2", x_axis, chart.prepare_data(y_axis2)) page.add(chart) return page
def test_boxplot(): # boxPlot default boxplot = Boxplot("箱形图") x_axis = ['expr1', 'expr2', 'expr3', 'expr4', 'expr5'] y_axis = [[ 850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960 ], [ 960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800 ], [ 880, 880, 880, 860, 720, 720, 620, 860, 970, 950, 880, 910, 850, 870, 840, 840, 850, 840, 840, 840 ], [ 890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780 ], [ 890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870 ]] _yaxis = boxplot.prepare_data(y_axis) boxplot.add("boxplot", x_axis, _yaxis) boxplot.render() # boxPlot two category boxplot = Boxplot("箱形图") x_axis = ['expr1', 'expr2'] y_axis1 = [ [ 850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960 ], [ 960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800 ], ] y_axis2 = [[ 890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780 ], [ 890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870 ]] boxplot.add("category1", x_axis, boxplot.prepare_data(y_axis1)) boxplot.add("category2", x_axis, boxplot.prepare_data(y_axis2)) assert "category1" in boxplot._repr_html_() assert "category2" in boxplot._repr_html_() boxplot.render()
def create_charts(): page = Page() style = Style(width=WIDTH, height=HEIGHT) chart = Boxplot("箱形图-单图例", **style.init_style) x_axis = ['expr1', 'expr2', 'expr3', 'expr4', 'expr5'] y_axis = [[ 850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960 ], [ 960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800 ], [ 880, 880, 880, 860, 720, 720, 620, 860, 970, 950, 880, 910, 850, 870, 840, 840, 850, 840, 840, 840 ], [ 890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780 ], [ 890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870 ]] _yaxis = chart.prepare_data(y_axis) chart.add("boxplot", x_axis, _yaxis) page.add(chart) chart = Boxplot("箱形图-多图例", **style.init_style) x_axis = ['expr1', 'expr2'] y_axis1 = [[ 850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960 ], [ 960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800 ]] y_axis2 = [[ 890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780 ], [ 890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870 ]] chart.add("category1", x_axis, chart.prepare_data(y_axis1)) chart.add("category2", x_axis, chart.prepare_data(y_axis2)) page.add(chart) return page
def prepare_data(list_x): list_y = [] for i in list_x: if len(i) >=3: list_y.extend(Boxplot.prepare_data([i])) if len(i) == 2: list_y.extend(Boxplot.prepare_data([[i[0]]+i+[i[1]]])) if len(i) == 1: list_y.extend(Boxplot.prepare_data([[i[0]]+i])) if len(i) == 0: list_y.extend(Boxplot.prepare_data([[0,0,0]])) return list_y
def boxplot1_fun(): boxplot = Boxplot("箱形图") x_axis = ['expr1', 'expr2', 'expr3', 'expr4', 'expr5'] y_axis = [[ 850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960 ], [ 960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800 ], [ 880, 880, 880, 860, 720, 720, 620, 860, 970, 950, 880, 910, 850, 870, 840, 840, 850, 840, 840, 840 ], [ 890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780 ], [ 890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870 ]] _yaxis = boxplot.prepare_data(y_axis) # 转换数据 boxplot.add("boxplot", x_axis, _yaxis) return boxplot
def boxplot(title, x, y, size=None): if size is None: scatter = Boxplot( title, width=320, height=180, title_pos="center", # background_color='#f0f0f0', ) else: scatter = Boxplot( title, width=size['width'], height=size['height'], title_pos="center", # background_color='#f0f0f0', ) """计算箱体参数 """ _yaxis = scatter.prepare_data(y) scatter.add("", x, _yaxis, is_visualmap=False, # mark_line=['average'], # mark_point=['max', 'min'], ) scatter.options['yAxis'][0]['splitArea'] = True scatter.options['xAxis'][0]['splitArea'] = False scatter.options['toolbox']['show'] = False return scatter.render_embed()
def picture_box(file_path): """ 绘制箱形图 :param file_path:数据文件的路径 """ birth_hcs = pd.read_csv(file_path) birth_col_hcs = birth_hcs.loc[:, [ 'INFANT_ALIVE_AT_REPORT', 'BIRTH_YEAR', 'INFANT_WEIGHT_GRAMS' ]] # 取反,去除不需要的数据 birth_nien_hcs = birth_col_hcs[~birth_col_hcs['INFANT_WEIGHT_GRAMS']. isin([9999])] # 按年分时间段 year_2014_hcs = birth_nien_hcs[birth_nien_hcs['BIRTH_YEAR'] == 2014] year_2015_hcs = birth_nien_hcs[birth_nien_hcs['BIRTH_YEAR'] == 2015] # 再分每年中,存活与死亡的 year_2014_y_hcs = year_2014_hcs[year_2014_hcs['INFANT_ALIVE_AT_REPORT'] == 'Y'] year_2014_n_hcs = year_2014_hcs[year_2014_hcs['INFANT_ALIVE_AT_REPORT'] == 'N'] year_2015_y_hcs = year_2015_hcs[year_2015_hcs['INFANT_ALIVE_AT_REPORT'] == 'Y'] year_2015_n_hcs = year_2015_hcs[year_2015_hcs['INFANT_ALIVE_AT_REPORT'] == 'N'] # 实例化一个箱形图对象 box_hcs = Boxplot('存活婴儿与死亡婴儿体重对比——箱型图(黄彩思)') # 使用自带的prepare_data计算所需的五个数 y_data_hcs = box_hcs.prepare_data([ year_2014_y_hcs['INFANT_WEIGHT_GRAMS'], year_2015_y_hcs['INFANT_WEIGHT_GRAMS'] ]) n_data_hcs = box_hcs.prepare_data([ year_2014_n_hcs['INFANT_WEIGHT_GRAMS'], year_2015_n_hcs['INFANT_WEIGHT_GRAMS'] ]) # 获取x_axis轴的数据:每个年度 x_axis_hcs = birth_nien_hcs.drop_duplicates( subset='BIRTH_YEAR')['BIRTH_YEAR'].sort_values() print('存活婴儿数据箱型图:', y_data_hcs, '\n', '死亡婴儿数据箱型图:', n_data_hcs) box_hcs.add('存活婴儿', x_axis=x_axis_hcs, y_axis=y_data_hcs) box_hcs.add('死亡婴儿', x_axis=x_axis_hcs, y_axis=n_data_hcs, legend_pos='right') box_hcs.render('box.html')
def feature_view_box(self,X): feature_name = X.columns.values page = Page() boxp = Boxplot() for f in feature_name: if self.category[f] == 1: boxp.add("",f,boxp.prepare_data([X[f].values])) page.add(boxp) page.render("/home/yhw/桌面/compa/光伏功率预测/feature_view_box.html")
def boxplot_demo(self): # 箱体图 from pyecharts import Boxplot boxplot = Boxplot("箱型图", "一年的降水量与蒸发量") x_axis = ['降水量', '蒸发量'] y_axis = [self.data1, self.data2] # prepare_data方法可以将数据转为嵌套的[min, Q1, median( or Q2), Q3, max] y_axis = boxplot.prepare_data(y_axis) boxplot.add("天气统计", x_axis, y_axis) boxplot.render('boxplot.html')
def boxplotpandas_fun(): boxplot = Boxplot("箱形图") df = pd.DataFrame( pd.read_csv('mycharts/class.csv', encoding='gbk', header=0)) df1 = pd.DataFrame(df['Height']) df2 = pd.DataFrame(df['Weight']) dtvalue1 = [i[0] for i in df1.values] dtvalue2 = [i[0] for i in df2.values] x_axis = ['身高', '体重'] y_axis = [dtvalue1, dtvalue2] _yaxis = boxplot.prepare_data(y_axis) # 转换数据 boxplot.add("箱形图", x_axis, _yaxis) return boxplot
def test_boxplot_one_legend(): boxplot = Boxplot("箱形图") x_axis = ['expr1', 'expr2', 'expr3', 'expr4', 'expr5'] y_axis = [ [850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960], [960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800], [880, 880, 880, 860, 720, 720, 620, 860, 970, 950, 880, 910, 850, 870, 840, 840, 850, 840, 840, 840], [890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780], [890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870] ] _yaxis = boxplot.prepare_data(y_axis) boxplot.add("boxplot", x_axis, _yaxis) boxplot.render()
def test_boxplot_two_legend(): boxplot = Boxplot("箱形图") x_axis = ['expr1', 'expr2'] y_axis1 = [ [850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960], [960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800], ] y_axis2 = [ [890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780], [890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870] ] boxplot.add("category1", x_axis, boxplot.prepare_data(y_axis1)) boxplot.add("category2", x_axis, boxplot.prepare_data(y_axis2)) html_content = boxplot._repr_html_() assert "category1" in html_content assert "category2" in html_content
def boxplotpandas1_fun(): boxplot = Boxplot("箱形图") df = pd.DataFrame( pd.read_csv('mycharts/class.csv', encoding='gbk', header=0)) df1 = df[df["Sex"] == "女"] df2 = df[df["Sex"] == "男"] dtvalue11 = df1['Height'].values.tolist() dtvalue12 = df1['Weight'].values.tolist() dtvalue21 = df2['Height'].values.tolist() dtvalue22 = df2['Weight'].values.tolist() x_axis = ['Height', 'Weight'] y_axis1 = [dtvalue11, dtvalue12] y_axis2 = [dtvalue21, dtvalue22] boxplot.add("女学生", x_axis, boxplot.prepare_data(y_axis1)) boxplot.add("男学生", x_axis, boxplot.prepare_data(y_axis2)) return boxplot
def edu(city, job): if city == '全国' or job == '': e = list(JobMsg.objects.all().values_list('job_xl', 'job_meanmoney')) else: e = list( JobMsg.objects.filter(job_name__icontains=job).values_list( 'job_xl', 'job_meanmoney')) # print(e) ee = [] for i in e: ee.append([i[0], int(i[1])]) # print(ee) try: edu = DataFrame(ee) edulist = {} for i in edu[0]: edulist[i] = list(edu.loc[edu[0] == i][1]) k = [] v = [] for key, value in edulist.items(): k.append(key) v.append(value) except: k = v = [] # print(k) # print('----',v) boxplot = Boxplot("学历与薪资水平箱线图", background_color='#', width=1000, height=350, title_text_size=18) _v = boxplot.prepare_data(v) # 转换数据 # print(_v) boxplot.add("boxplot", k, _v, xaxis_name='学历') return boxplot
j = ((float(j.split('-')[0].replace('k', '').replace('K', '')) + float(j.split('-')[1].replace('k', '').replace('K', ''))) / 2) * 1000 if i in ['天使轮']: dom1.append(j) elif i in ['A轮']: dom2.append(j) elif i in ['B轮']: dom3.append(j) elif i in ['C轮']: dom4.append(j) elif i in ['D轮及以上']: dom5.append(j) elif i in ['上市公司']: dom6.append(j) elif i in ['未融资']: dom7.append(j) else: dom8.append(j) boxplot = Boxplot("拉勾网数据分析岗—公司状态薪水图(元/月)", title_pos='center', title_top='18', width=1200, height=600) boxplot.use_theme("chalk") x_axis = ['天使轮', 'A轮', 'B轮', 'C轮', 'D轮及以上', '上市公司', '未融资', '不需要融资'] y_axis = [dom1, dom2, dom3, dom4, dom5, dom6, dom7, dom8] _yaxis = boxplot.prepare_data(y_axis) boxplot.add("", x_axis, _yaxis) boxplot.render("拉勾网数据分析岗—公司状态薪水图.html")
boxplot = Boxplot("箱形图") x_axis = ['expr1', 'expr2'] y_axis1 = [ [850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960], [960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800], ] y_axis2 = [ [890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780], [890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870] ] print(boxplot.prepare_data(y_axis1)) boxplot.add("category1", x_axis, boxplot.prepare_data(y_axis1)) boxplot.add("category2", x_axis, boxplot.prepare_data(y_axis2)) boxplot.render() # K line from pyecharts import Kline v1 = [[2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38], [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8], [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82], [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38], [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73], [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03],
import pandas as pd from pyecharts import Boxplot data = pd.read_csv(r"C:\学习\python数据分析\数据\iris-data.csv") x = list(data.columns[0:4]) y = [ list(data.sepal_length_cm), list(data.sepal_width_cm), list(data.petal_length_cm), list(data.petal_width_cm) ] boxplot = Boxplot("箱线图") y_data = boxplot.prepare_data(y) boxplot.add("", x, y_data) boxplot.render()
for i in x_axis2: v = [] for j in x_axis: dfv = pde.drop_outliers(df.loc[(df[x_attr] == i) & (df[y_attr] == j), :], ['profits']) # hack v.append(list(dfv['profits'])) data.append(v) from pyecharts import Boxplot title = 'Profits of movie with different rating and score' boxplot = Boxplot(title, title_pos='center') p = 0 for i in x_axis2: boxplot.add(i, x_axis, boxplot.prepare_data(data[p]), legend_top='7%') p += 1 boxplot.render(title + '.html') ############################################################################# ################ smart heatmap ########################################### from pyecharts import HeatMap from pyecharts import Page def ref_list_maker(df, attr1, attr2): # df is a grouped table x_axis = list(set(df[attr1])) y_axis = list(set(df[attr2]))
960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800 ], [ 880, 880, 880, 860, 720, 720, 620, 860, 970, 950, 880, 910, 850, 870, 840, 840, 850, 840, 840, 840 ], [ 890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780 ], [ 890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870 ]] _yaxis = boxplot.prepare_data(y_axis) # 转换数据 boxplot.add("boxplot", x_axis, _yaxis) # boxplot.render() # In[71]: from pyecharts import Boxplot boxplot = Boxplot("箱形图") x_axis = ['expr1', 'expr2'] y_axis1 = [ [ 850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960 ], [
#箱型图适合表现一组数据的统计分布规律,它能显示出一组数据的最大值、最小值、中位数、及上下四分位数。 from pyecharts import Boxplot x =['1班','2班','3班','4班'] y1=[78, 98, 56, 78, 90.0, 45, 78, 20, 87, 86, 74, 89, 94] y2=[89, 82, 45, 67, 68, 78.0, 79, 98, 71, 56, 78, 81, 80] y3=[90, 80, 60, 89, 76, 73.0, 72, 92, 89, 87, 65, 66, 76] y4=[82, 72, 55, 100, 90.0, 78, 69, 67, 87, 66, 78, 71, 82] box = Boxplot(title = '考试成绩箱型图',width = 600,height = 420) # 预处理数据计算最大值,最小值,中位数以及上下四分位数 y_prepared = box.prepare_data([y1,y2,y3,y4]) box.add(name = '',x_axis = x,y_axis = y_prepared) box.render('result.箱型图示范.html') #箱型图的进阶版本是小提琴图,可以展示数据的密度估计曲线,可以用seaborn画出。 import seaborn as sns # %matplotlib inline # %config InlineBackend.figure_format = 'svg' #设置风格 sns.set(style="white", context="notebook") #处理中文问题 sns.set_style({'font.sans-serif':['simhei', 'Arial']})
def plot(self): u""" Do a echarts plot to view all the conditions :return: """ def custom_formatter(params): return params.value[3] + ": " + params.value[1] line = Line("", width="100%", height=800) attr = sorted([x["Name"] for x in self.data]) names = [x for x in self.name[5:] if x] data = [] for idx, i in enumerate(sorted(names)): if not i: continue tmp_value = [] extra_name = [] for x in self.data: tmp = self.meta.get(x["Name"], "NA") if isinstance(tmp, dict): tmp.get("tissue", "NA") extra_name.append("%s (%s)" % (x["Name"], tmp)) if x[i].endswith("%"): tmp_value.append(float(x[i].replace("%", ""))) else: tmp_value.append(int(x[i].replace(",", ""))) line.add( i, attr, tmp_value, is_datazoom_show=True, datazoom_type="both", datazoom_range=[0, 100], is_datazoom_extra_show=True, xaxis_rotate=30, ) boxplot = Boxplot(i, width="60%", height=800) boxplot.add(i, [i], boxplot.prepare_data([tmp_value]), is_legend_show=False, tooltip_formatter=custom_formatter, is_datazoom_extra_show=True, datazoom_extra_range=[0, 100]) scatter = Scatter(width="60%", height=800) scatter.add(i, extra_name, tmp_value, extra_data=extra_name, extra_name=extra_name, is_legend_show=False, tooltip_formatter=custom_formatter, is_datazoom_extra_show=True, datazoom_extra_range=[0, 100], xaxis_type="category", xaxis_rotate=45) grid = Grid( width="100%", height=600, ) grid.add(scatter, grid_right="25%", grid_bottom="25%") grid.add(boxplot, grid_left="80%", grid_bottom="25%") data.append(grid) grid = Page() grid.add(line) for i in data: grid.add(i) grid.render(self.output)
gauge =Gauge('目标完成率') gauge.add('任务指标','完成率',90) gauge.render('目标完成率.html') # # # # # # 箱线图 Titanic = pd.read_csv('titanic_train.csv') #检查年龄是否有缺失 any(Titanic['Age'].isnull()) # 删除缺失值 Titanic['Age'].dropna(inplace=True) from pyecharts import Boxplot boxplot = Boxplot('年龄箱线图') x_axis = ['年龄'] y_axis = Titanic['Age'].values y_axis = list(np.reshape(y_axis,(1,-1))) _yaxis = boxplot.prepare_data(y_axis) #必须要将数据进行转换 boxplot.add('箱线图',x_axis,_yaxis) boxplot.render('boxplot.html') # # #子图 from pyecharts import Line, Pie, Grid line = Line("折线图示例", width=1200) attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"]) line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"], mark_line=["average"], legend_pos="20%") attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [11, 12, 13, 10, 10, 10] pie = Pie("饼图示例", title_pos="45%")
# In[ ]: from pyecharts import Boxplot #字段重命名 df.columns = [ 'satisfaction', 'evaluation', 'project', 'hours', 'years_work', 'work_accident', 'left', 'promotion', 'department', 'salary' ] #绘制箱线图 boxplot = Boxplot("对公司满意度与是否离职关系图", title_pos='center') x_axis = ['在职', '离职'] y_axis = [ df[df.left == 0].satisfaction.values, df[df.left == 1].satisfaction.values ] boxplot.add("", x_axis, boxplot.prepare_data(y_axis)) boxplot.render() # ### 3. 最新考核评估与是否离职的关系 # In[ ]: boxplot = Boxplot("最新评估与是否离职关系图", title_pos='center') x_axis = ['在职', '离职'] y_axis = [ df[df.left == 0].evaluation.values, df[df.left == 1].evaluation.values ] boxplot.add("", x_axis, boxplot.prepare_data(y_axis)) boxplot.render() # ### 4. 所参加项目与是否离职的关系