第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

Bokeh數(shù)據(jù)可視化工具2繪圖進階

標簽:
Python

其他数据结构绘图

使用numpy创建线状图

#Creating line plots using NumPy arrays#Import required packagesimport numpy as npimport randomfrom bokeh.io import output_file, showfrom bokeh.plotting import figure#Creating an array for the points along the x and y axesarray_x =np.array([1,2,3,4,5,6])
array_y = np.array([5,6,7,8,9,10])#Creating a line plotplot = figure()
plot.line(array_x, array_y)#Output the plotoutput_file('numpy_line.html')
show(plot)

webp

image.png

使用numpy创建散列图

#Creating scatter plots using NumPy arrays#Import required packagesimport numpy as npimport randomfrom bokeh.io import output_file, showfrom bokeh.plotting import figure#Creating arrays for two different categories of pointsx_red = np.array([1,2,3,4,5])
y_red = np.array([5,6,7,8,9])
x_blue = np.array([10,11,12,13])
y_blue = np.array([14,15,16,17])#Creating the categorical scatter plot plot = figure()
plot.circle(x_red, y_red, size = 9, color = 'red', alpha = 0.8)
plot.circle(x_blue, y_blue, size = 9, color = 'blue', alpha = 0.8)#Output the plot output_file('numpy_scatter.html')
show(plot)

webp

image.png

使用pandas DataFrame创建时序图

苹果股票的高值:

#Creating a time series plot using a Pandas DataFrame#Importing the required packagesimport pandas as pd#Read in the datadf = pd.read_csv('/home/andrew/code/kaggle-code/stock_data/all_stocks_5yr.csv')#Filtering for apple stocksdf_apple = df[df['Name'] == 'AAL']#df_apple.loc['date'] = df_apple['date'].astype('datetime64')df_apple['date'] = pd.to_datetime(df_apple['date'])
print(df_apple.dtypes)#Import the required packagesfrom bokeh.io import output_file, showfrom bokeh.plotting import figure#Create the time series plotplot = figure(x_axis_type = 'datetime', x_axis_label = 'date', y_axis_label = 'High Prices')
plot.line(x = df_apple['date'], y = df_apple['high'])#Output the plotoutput_file('pandas_time.html')
show(plot)

webp

image.png

  • 参考资料

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.astype.html
https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas

另外一个更简单的演示:

import pandas as pdimport numpy as npfrom bokeh.plotting import figure, output_file, showfrom bokeh.layouts import row

output_file('fig.html')

test = pd.DataFrame({'datetime':pd.date_range('1/1/1880', periods=2000),'foo':np.arange(2000)})

print(test['datetime'])

fig = figure(x_axis_type="datetime")
fig.line(x='datetime',y='foo', source=test)

test = test.set_index('datetime')

fig2 = figure(x_axis_type="datetime")
fig2.line(x='datetime', y='foo', source=test)
show(row(fig, fig2))

webp

image.png

  • 参考资料

https://stackoverflow.com/questions/34974615/timeseries-in-bokeh-using-a-dataframe-with-index

https://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html

https://github.com/CNuge/kaggle-code

  • 同一行创建多个图

  • 同一列创建多个图

  • 行和列中创建多个图

  • 选项卡式布局创建多个绘图

  • 创建强大的网格布局

  • 将多个图表链接在一起

同一行创建多个图

bokeh自带了很多数据,可以用如下方式下载:

In [2]: import bokeh

In [3]: bokeh.sampledata.download()
Creating /home/andrew/.bokeh directory
Creating /home/andrew/.bokeh/data directory
Using data directory: /home/andrew/.bokeh/data
Downloading: CGM.csv (1589982 bytes)   1589982 [100.00%]
Downloading: US_Counties.zip (3182088 bytes)   3182088 [100.00%]
Unpacking: US_Counties.csv
Downloading: us_cities.json (713565 bytes)    713565 [100.00%]
Downloading: unemployment09.csv (253301 bytes)    253301 [100.00%]
Downloading: AAPL.csv (166698 bytes)    166698 [100.00%]
Downloading: FB.csv (9706 bytes)      9706 [100.00%]
Downloading: GOOG.csv (113894 bytes)    113894 [100.00%]
Downloading: IBM.csv (165625 bytes)    165625 [100.00%]
Downloading: MSFT.csv (161614 bytes)    161614 [100.00%]
Downloading: WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.zip (5148539 bytes)   5148539 [100.00%]
Unpacking: WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.csv
Downloading: gapminder_fertility.csv (64346 bytes)     64346 [100.00%]
Downloading: gapminder_population.csv (94509 bytes)     94509 [100.00%]
Downloading: gapminder_life_expectancy.csv (73243 bytes)     73243 [100.00%]
Downloading: gapminder_regions.csv (7781 bytes)      7781 [100.00%]
Downloading: world_cities.zip (646858 bytes)    646858 [100.00%]
Unpacking: world_cities.csv
Downloading: airports.json (6373 bytes)      6373 [100.00%]
Downloading: movies.db.zip (5067833 bytes)   5067833 [100.00%]
Unpacking: movies.db
Downloading: airports.csv (203190 bytes)    203190 [100.00%]
Downloading: routes.csv (377280 bytes)    377280 [100.00%]
#Preparing all the plots needed for this chapterimport pandas as pdfrom bokeh.sampledata.stocks import AAPL

df_apple = pd.DataFrame(AAPL)
df_apple['date'] = pd.to_datetime(df_apple['date'])#Import the required packagesfrom bokeh.io import output_file, showfrom bokeh.plotting import figurefrom bokeh.plotting import ColumnDataSource#Create the ColumnDataSource objectdata = ColumnDataSource(data = {    'x' : df_apple['high'],    'y' : df_apple['low'],    'x1': df_apple['open'],    'y1': df_apple['close'],    'x2': df_apple['date'],    'y2': df_apple['volume'], 
})#Create the first scatter plotplot1 = figure()
plot1.cross(x = 'x', y = 'y', source = data, color = 'red', size = 10, alpha = 0.8)#Create the second scatter plotplot2 = figure()
plot2.circle(x = 'x1', y = 'y1', source = data, color = 'green', size = 10, alpha = 0.3)#Create the third scatter plotplot3 = figure(x_axis_type = 'datetime', x_axis_label = 'date', y_axis_label = 'Volume Traded')
plot3.line(x = 'x2', y = 'y2', source = data, color = 'red')
plot3.circle(x = 'x2', y = 'y2', source = data, fill_color = 'white', size = 3)#Output the 3 plots#Output the plot1output_file('first_plot.html')
show(plot1)#Output the plot2output_file('second_plot.html')
show(plot2)#Output the plot3output_file('third_plot.html')
show(plot3)#Creating multiple plots along the same row#Import the required packagesfrom bokeh.layouts import rowfrom bokeh.io import output_file, show#Group the 3 plots into a 'row' layoutrow_layout = row(plot1,plot2,plot3)#Output the plotoutput_file('horizontal.html')
show(row_layout)#Creating multiple plots along the same column#Import the required packagesfrom bokeh.layouts import columnfrom bokeh.io import output_file, show#Group the 2 plots into a 'column' layoutcol_layout = column(plot1,plot2)#Output the plotoutput_file('vertical.html')
show(col_layout)#Creating multiple plots along a row and column#Import the required packagesfrom bokeh.layouts import column, rowfrom bokeh.io import output_file, show#Construct the nested layoutnested_layout = column(row(plot1,plot2), plot3)#Output the plotoutput_file('nested.html')
show(nested_layout)#Creating multiple plots on a tabbed layout#Import the required packagesfrom bokeh.models.widgets import Tabs, Panelfrom bokeh.io import output_file, showfrom bokeh.layouts import column, row#Create the two panels tab1 = Panel(child = plot1, title = 'Tab One')
tab2 = Panel(child = column(plot2,plot3), title = 'Tab Two')#Feed the tabs into a Tabs objecttabs_object = Tabs(tabs = [tab1, tab2])#Output the plotoutput_file('tab_layout.html')
show(tabs_object)#Creating a grid layout#Import required packagesfrom bokeh.io import output_file, showfrom bokeh.layouts import gridplot#Create the grid layoutgrid_layout = gridplot([plot1, plot2], [plot3, None])#Output the plotoutput_file('grid.html')
show(grid_layout)#Linking multiple plots along the y axis#Import the required packagesfrom bokeh.io import output_file, showfrom bokeh.layouts import row#Creating equal y axis rangesplot3.y_range = plot1.y_range#Create the row layoutrow_layout = row(plot3, plot1)#Output the plotoutput_file('grid.html')
show(row_layout)#Linking multiple plots along the x axis#Import the required packagesfrom bokeh.io import output_file, showfrom bokeh.layouts import row#Creating equal x-axis rangesplot2.x_range = plot1.x_range#Create the row layoutrow_layout = row(plot2, plot1)#Output the plotoutput_file('row.html')
show(row_layout)

webp

图片.png

webp

图片.png

webp

图片.png

webp

图片.png

webp

图片.png

webp

图片.png

webp

图片.png

webp

图片.png

webp

图片.png

webp



作者:python作业AI毕业设计
链接:https://www.jianshu.com/p/33b8ce521d7a


點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消