name是什么牌子羽绒服,name是什么中文意思
关于pyechartspyecharts是一个用于生成电子海图(百度开源的数据可视化爪哇岛描述语言库)图表的类库肾盂造影图分为v0.5.x和v1.x两个大版本,版本不兼容,本篇所有的案例基于v1.6.2。
回到顶部
柱状图
# 柱状图导入随机导入pye图表。pye图表中的选项。图表导入Barx _ vals='衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子bar=( Bar().add_xaxis(x_vals).add_yaxis('商家一个',)。add_yaxis('商家b ',).add_yaxis('商家c ',).add_yaxis('商家d ',).set _ series _ opts(label _ opts=opts .LabelOpts(is_show=True,font_size=14),markline_opts=opts .MarkLineOpts(data=).set _ global _ opts(title _ opts=opts .TitleOpts(title='柱状图示例-销量,subtitle='四个商家),xaxis_opts=opts .AxisOpts(name='商品),yaxis_opts=opts .AxisOpts(name='单位:件)))bar.render('柱状图. html')
回到顶部
堆叠柱状图
# 柱状堆叠图将pyecharts.options作为选项从pyecharts .图表导入Bargoods='衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子bar=( Bar().add_xaxis(货物)。add_yaxis('商家a ',stack='stack1 ').add_yaxis('商家b ',stack='stack1 ').add_yaxis('商家c ',stack='stack1 ').set _ series _ opts(label _ opts=opts .LabelOpts(is_show=False)).set _ global _ opts(title _ opts=opts .TitleOpts(title='柱状堆叠图示例-商品销量),xaxis_opts=opts .AxisOpts(name='品类),yaxis_opts=opts .AxisOpts(name='销量(单位:件)')))bar.render('柱
状堆叠图.html')回到顶部
条形图
# 条形图x_vals1 = x_vals2 = x_vals3 = y_vals = bar = Bar().add_xaxis(x_vals1 + x_vals2 + x_vals3) bar.add_yaxis('商家A', y_vals, markpoint_opts=opts.MarkPointOpts(data=, symbol_size=80) ) bar.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='right'))bar.set_global_opts(title_opts=opts.TitleOpts(title='条形图示例-商品销量', subtitle='条目较多条形图比较好看点'))bar.reversal_axis() #翻转XY轴,将柱状图转换为条形图bar.render('条形图.html')
回到顶部
直方图
# 直方图# 直方图import randomimport pyecharts.options as optsfrom pyecharts.charts import Barx_vals = xlen = len(x_vals)# 设置成两种颜色y_vals = for idx, item in enumerate(x_vals): if idx % 2 == 0: y_vals.append( opts.BarItem( name = item, value = random.randint(10, 100), itemstyle_opts = opts.ItemStyleOpts(color="#749f83"), ) ) else: y_vals.append( opts.BarItem( name = item, value = random.randint(10, 100), itemstyle_opts = opts.ItemStyleOpts(color="#d48265"), ) )bar_histogram = ( Bar() .add_xaxis(x_vals) .add_yaxis('商家A', y_vals, category_gap=0) # .add_yaxis('商家A', , category_gap=0) .set_series_opts(label_opts=opts.LabelOpts(is_show=True, font_size=14)) .set_global_opts(title_opts=opts.TitleOpts(title='直方图示例-选择赠品', subtitle=''), xaxis_opts=opts.AxisOpts(name='赠品类型'), yaxis_opts=opts.AxisOpts(name='选择相应赠品的人数')))bar_histogram.render('直方图.html')
回到顶部
帕累托图(复合图)
# 帕累托图--# 左边纵坐标表示频数,右边纵坐标表示频率.分析线表示累积频率import randomfrom pyecharts import options as optsfrom pyecharts.charts import Bar, Lineimport pandas as pd# 随机颜色, from fakerdef rand_color() -> str: return random.choice( )df_origin = pd.DataFrame({'categories':,'sales': })print(df_origin)# 按销量降序排列df_sorted = df_origin.sort_values(by='sales' , ascending=False)print(df_sorted)# 折线图x轴x_line_categories = # 折线图y轴--向下累积频率cum_percent = df_sorted.cumsum() / df_sorted.sum() * 100cum_percent = cum_percent.append(pd.Series()) # 添加起始频率0cum_percent = cum_percent.sort_values(ascending=True)print(df_sorted.categories.values.tolist()) print(cum_percent.values.tolist())def pareto_bar() -> Bar: line = ( Line() .add_xaxis(x_line_categories) .add_yaxis("累计百分比", cum_percent.values.tolist(), xaxis_index=1, yaxis_index=1, # 使用次y坐标轴,即bar中的extend_axis label_opts=opts.LabelOpts(is_show=False), is_smooth=True, ) ) bar = ( Bar() .add_xaxis(df_sorted.categories.values.tolist()) .add_yaxis('销售额', df_sorted.sales.values.tolist(), category_gap=0) # .add_yaxis('总额百分比', cum_percent.values.tolist()) .extend_axis(xaxis=opts.AxisOpts(is_show=False, position='top')) .extend_axis(yaxis=opts.AxisOpts(axistick_opts=opts.AxisTickOpts(is_inside=True), # 刻度尺朝内 axislabel_opts=opts.LabelOpts(formatter='{value}%'), position='right') ) .set_series_opts(label_opts=opts.LabelOpts(is_show=True, font_size=14)) .set_global_opts(title_opts=opts.TitleOpts(title='帕累托图示例-销售额', subtitle=''), xaxis_opts=opts.AxisOpts(name='商品类型', type_='category'), yaxis_opts=opts.AxisOpts( axislabel_opts=opts.LabelOpts(formatter="{value} 件") ) ) ) bar.overlap(line) return barpareto_bar().render('帕累托图.html')
回到顶部
饼图
# 饼图from pyecharts import options as optsfrom pyecharts.charts import Page, Piepie = ( Pie() .add('鼠标选中分区后的tip', # count 2 ,)>) # count 8 .set_series_opts(label_opts=opts.LabelOpts(formatter='{b}: {c}万套')) .set_global_opts(title_opts=opts.TitleOpts(title='饼图实例-近两年季度销售'), legend_opts=opts.LegendOpts(is_show=False)))pie.render('饼图.html')
回到顶部
圆环图
from pyecharts.charts import Piepie = ( Pie() .add( '鼠标选中分区后的tip', # count 2 ,)>, radius=, #设置内径外径 label_opts=opts.LabelOpts(is_show=True) ) .set_global_opts(title_opts=opts.TitleOpts(title='圆环图示例-近两年季度销售'), legend_opts=opts.LegendOpts(is_show=False)))pie.render('圆环图.html')
回到顶部
玫瑰图
# 玫瑰图from pyecharts.charts import Piepie = ( Pie() .add( '鼠标选中分区后的tip', # count 2 ,)>, radius=, #设置内径外径 # rosetype='radius' 圆心角展现数据百分比,半径展现数据大小 # rosetype='area' 圆心角相同,为通过半径展现数据大小 rosetype='radius', label_opts=opts.LabelOpts(is_show=True) ) .set_global_opts(title_opts=opts.TitleOpts(title='玫瑰图示例-近两年季度销售'), legend_opts=opts.LegendOpts(is_show=False)))pie.render('玫瑰图.html')
回到顶部
折线图
# 折线图import randomimport pyecharts.options as optsfrom pyecharts.charts import Linefrom pyecharts.commons.utils import JsCode line = ( Line() .add_xaxis() # 1-4周 .add_yaxis('A题', , is_smooth=True, # 平滑 markpoint_opts=opts.MarkPointOpts( # 使用coord这个属性设置自定义标记点数值,我这儿随便写 data=
回到顶部
折线面积图
# 折线面积图import randomimport pyecharts.options as optsfrom pyecharts.charts import Linefrom pyecharts.commons.utils import JsCode line = ( Line() .add_xaxis() # 1-4周 .add_yaxis('蔡队', , is_symbol_show=False, areastyle_opts=opts.AreaStyleOpts(opacity=0.5), markpoint_opts=opts.MarkPointOpts(data=, symbol_size=50) ) .add_yaxis('旺神', , is_smooth=True, is_symbol_show=False, areastyle_opts=opts.AreaStyleOpts(opacity=0.5) ) .set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-30)), # 设置x轴标签旋转角度 yaxis_opts=opts.AxisOpts(name='完成积分', min_=5), title_opts=opts.TitleOpts(title='折线面积图示例_周赛分析')) )line.render('折线面积图.html')
回到顶部
散点图
# 散点图from pyecharts.charts import Scatterfrom pyecharts import options as optsfrom pyecharts.commons.utils import JsCodeimport pandas as pddef scatter_simple() -> Scatter: # 数据源 df = pd.DataFrame({'AC':, # 刷题数 'ACB':, '姓名':}) # inplace=True:不创建新的对象,直接对原始对象进行修改 # 升序 df.sort_values('AC', inplace=True, ascending=True) c = ( Scatter() .add_xaxis(df.AC.values.tolist()) .add_yaxis( '刷题_能力_姓名', df<>.values.tolist(), label_opts=opts.LabelOpts( formatter=JsCode( 'function(params){return params.value;}' #通过定义JavaScript回调函数自定义标签 ) ) ) .set_global_opts( title_opts=opts.TitleOpts(title='散点图示例--ACM集训队队员能力'), xaxis_opts=opts.AxisOpts(name='AC(刷题数)', type_='value', min_=20), #x轴从20开始,原点不为0 yaxis_opts=opts.AxisOpts(name='ACB(能力值)', min_=100), # y轴起始点的值 legend_opts=opts.LegendOpts(is_show=True) ) ) return cscatter_simple().render('散点图.html')
回到顶部
雷达图
# 雷达图import randomfrom pyecharts import options as optsfrom pyecharts.charts import Page, Radardef radar_simple() -> Radar: c = ( Radar() .add_schema( # 各项的max_值可以不同 schema= ) .add('旺神', <>, color='red', areastyle_opts = opts.AreaStyleOpts( #设置填充的属性 opacity = 0.5, color='red' ),) .add('蔡队', <>, color='blue', areastyle_opts = opts.AreaStyleOpts( opacity = 0.5,#透明度 color='blue' ),) .set_series_opts(label_opts=opts.LabelOpts(is_show=True)) .set_global_opts(title_opts=opts.TitleOpts(title='雷达图示例-ACM集训队队员能力')) ) return cradar_simple().render('雷达图.html')
回到顶部
箱线图
# 箱线图--描述离散程度from pyecharts import options as optsfrom pyecharts.charts import Boxplotdef boxpolt_base() -> Boxplot: v_sophomore = < , > v_junior = < , > # 最小值,下四分位数,中位数、上四分位数、最大值 # c = ( Boxplot() .add_xaxis() .add_yaxis('大二队员', Boxplot.prepare_data(v_sophomore)) .add_yaxis('大三队员', Boxplot.prepare_data(v_junior)) .set_series_opts(label_opts=opts.LabelOpts(is_show=True)) .set_global_opts(title_opts=opts.TitleOpts(title='ACM集训队祖传练习完成时长离散度'), xaxis_opts=opts.AxisOpts(name='单位:小时'), legend_opts=opts.LegendOpts(is_show=True)) .reversal_axis() #翻转XY轴 ) return cboxpolt_base().render('箱线图.html')
回到顶部
词云图
# 词云图from pyecharts import options as optsfrom pyecharts.charts import WordCloudfrom pyecharts.globals import SymbolTypewords = def wordcloud_base() -> WordCloud: c = ( WordCloud() .add("", words, word_size_range=, shape=SymbolType.ROUND_RECT) .set_global_opts(title_opts=opts.TitleOpts(title='WordCloud示例-OJ搜索关键字')) ) return cwordcloud_base().render('词云图.html')