from bokeh.plotting import figure, show from bokeh.models import ColumnDataSource, FactorRange from bokeh.transform import factor_cmap from bokeh.palettes import Blues from bokeh.io import output_notebook

bins=[0,143,353,1873,5149] df1=df[df['subscribe']=='yes'] binning=pd.cut(df1['duration'],bins,right=False) time=pd.value_counts(binning)

time=time.sort_index() time_percent = [f"{(i/sum(time)*100):.1f}%" for i in time.values]

source = ColumnDataSource(data=dict(x=time.index.tolist(), y=time.values, percent=time_percent))

p = figure(x_range=FactorRange(factors=time.index.tolist()), plot_height=250, plot_width=500, title="duration_yes", toolbar_location=None, tools="") p.vbar(x='x', top='y', width=0.9, source=source, line_color='white', fill_color=factor_cmap('x', palette=Blues[4], factors=time.index.tolist()))

p.xgrid.grid_line_color = None p.y_range.start = 0 p.xaxis.major_label_orientation = 1.2 p.xaxis.axis_label_text_font_size = "8pt" p.yaxis.axis_label_text_font_size = "0pt" p.yaxis.major_label_text_font_size = "0pt" p.xaxis.axis_label = "Duration" p.xaxis.axis_label_text_font_size = "8pt" p.title.align = "center" p.title.text_font_size = "8pt"

labels = LabelSet(x='x', y='y', text='percent', level='glyph', x_offset=-13.5, y_offset=0, source=source, render_mode='canvas', text_font_size='8pt') p.add_layout(labels)

output_notebook() show(p

import matplotlibpyplot as plt import seaborn as snsbins=014335318735149df1=dfdfsubscribe==yesbinning=pdcutdf1durationbinsright=Falsetime=pdvalue_countsbinning# 可视化time=timesort_indexfig=pltfigu

原文地址: https://www.cveoy.top/t/topic/e9zJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录