Travel Tips
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
折线图, 单线图、多线图
单线图、多线图
import numpy as np import pandas as pd import matplotlib.pyplot as plt %matplotlib inline import warnings warnings.filterwarnings('ignore') # 不发出警告
from bokeh.io import output_notebook output_notebook() # 导入notebook绘图模块 from bokeh.plotting import figure,show
from bokeh.models import ColumnDataSource # 导入ColumnDataSource模块 # 将数据存储为ColumnDataSource对象 # 参考文档:http://bokeh.pydata.org/en/latest/docs/user_guide/data.html # 可以将dict、Dataframe、group对象转化为ColumnDataSource对象 df = pd.DataFrame({'value':np.random.randn(100).cumsum()}) # 创建数据 df.index.name = 'index' source = ColumnDataSource(data = df) # 转化为ColumnDataSource对象 # 这里注意了,index和columns都必须有名称字段 p = figure(plot_width=600, plot_height=400) p.line(x='index',y='value',source = source, # 设置x,y值, source → 数据源 line_width=1, line_alpha = 0.8, line_color = 'black',line_dash = [10,4]) # 线型基本设置 # 绘制折线图 p.circle(x='index',y='value',source = source, size = 2,color = 'red',alpha = 0.8) # 绘制折点 也就是一个散点图 show(p)
df = pd.DataFrame({'A':np.random.randn(100).cumsum(),"B":np.random.randn(100).cumsum()}) # 创建数据 p = figure(plot_width=600, plot_height=400) p.multi_line([df.index, df.index], [df['A'], df['B']], # 注意x,y值的设置 → [x1,x2,x3,..], [y1,y2,y3,...] color=["firebrick", "navy"], # 可同时设置 → color= "firebrick" alpha=[0.8, 0.6], # 可同时设置 → alpha = 0.6 line_width=[2,1], # 可同时设置 → line_width = 2 ) # 绘制多段线 # 这里由于需要输入具体值,故直接用dataframe,或者dict即可 show(p)
x = np.linspace(0.1, 5, 100) # 创建x值 p = figure(title="log axis example", y_axis_type="log",y_range=(0.001, 10**22)) # 这里设置对数坐标轴 p.line(x, np.sqrt(x), legend_label="y=sqrt(x)", line_color="tomato", line_dash="dotdash") # line1 p.line(x, x, legend_label="y=x") p.circle(x, x, legend_label="y=x") # line2,折线图+散点图 p.line(x, x**2, legend_label="y=x**2") p.circle(x, x**2, legend_label="y=x**2",fill_color=None, line_color="olivedrab") # line3 p.line(x, 10**x, legend_label="y=10^x",line_color="gold", line_width=2) # line4 p.line(x, x**x, legend_label="y=x^x",line_dash="dotted", line_color="indigo", line_width=2) # line5 p.line(x, 10**(x**2), legend_label="y=10^(x^2)",line_color="coral", line_dash="dashed", line_width=2) # line6 p.legend.location = "top_left" p.xaxis.axis_label = 'Domain' p.yaxis.axis_label = 'Values (log scale)' # 设置图例及label show(p)
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Donec in ullamcorper quam. Aenean vel nibh eu magna gravida fermentum. Praesent eget nisi pulvinar, sollicitudin eros vitae, tristique odio.
December 4, 2020 at 3:12 pm
我是 s enim interduante quis metus. Duis porta ornare nulla ut bibendum
Rosie
6 minutes ago