一、Matplotlib繪圖
折線圖
import matplotlib.pyplot as plt # 調(diào)用畫圖庫
plt.rcParams['font.sans-serif'] = ['SimHei'] # 設(shè)置成可以顯示中文,字體為黑體
plt.figure(figsize=(12,8)) # 調(diào)整圖片尺寸
x = ['周一','周二','周三','周四','周五','周六','周日'] # 設(shè)置x軸數(shù)據(jù)
y = [401,632,453,894,775,646,1207] # 設(shè)置對應(yīng)的y軸數(shù)據(jù)
plt.tick_params(labelsize=21) # 設(shè)置坐標(biāo)軸刻度的字體大小
plt.xlabel('日期', fontsize=24, labelpad=20) # 設(shè)置x軸標(biāo)簽
plt.ylabel('播放次數(shù)', fontsize=24) # 設(shè)置y軸標(biāo)簽
plt.title('視頻周播放量數(shù)據(jù)—宣一名', fontsize=35, pad=45) # 設(shè)置標(biāo)題
plt.plot(x,y, label = "播放次數(shù)",color='r',marker='s' ) # 繪制圖形
plt.legend(fontsize=20)
plt.show() # 展示圖形,在Jupyter中,可省略本行

柱狀圖
import matplotlib.pyplot as plt # 調(diào)用畫圖庫
plt.rcParams['font.sans-serif'] = ['SimHei'] # 設(shè)置成可以顯示中文,字體為黑體
plt.figure(figsize=(12,8)) # 調(diào)整圖片尺寸
x = ['周一','周二','周三','周四','周五','周六','周日'] # 設(shè)置x軸數(shù)據(jù)
y = [401,632,453,894,775,646,1207] # 設(shè)置對應(yīng)的y軸數(shù)據(jù)
plt.tick_params(labelsize=21) # 設(shè)置坐標(biāo)軸刻度的字體大小
plt.xlabel('日期', fontsize=24, labelpad=20) # 設(shè)置x軸標(biāo)簽
plt.ylabel('播放次數(shù)', fontsize=24) # 設(shè)置y軸標(biāo)簽
plt.title('視頻周播放量數(shù)據(jù)—宣一名', fontsize=35, pad=45) # 設(shè)置標(biāo)題
plt.plot(x,y, label = "播放次數(shù)",color='r',marker='s' ) # 繪制圖形
plt.legend(fontsize=20)
plt.show() # 展示圖形,在Jupyter中,可省略本行c

環(huán)形圖
import matplotlib.pyplot as plt # 調(diào)用畫圖庫
plt.rcParams['font.sans-serif'] = ['SimHei'] # 設(shè)置成可以顯示中文,字體為黑體
plt.figure(figsize=(12,8)) # 調(diào)整圖片尺寸
x = ['周一','周二','周三','周四','周五','周六','周日'] # 設(shè)置x軸數(shù)據(jù)
y = [401,632,453,894,775,646,1207] # 設(shè)置對應(yīng)的y軸數(shù)據(jù)
plt.tick_params(labelsize=21) # 設(shè)置坐標(biāo)軸刻度的字體大小
plt.xlabel('日期', fontsize=24, labelpad=20) # 設(shè)置x軸標(biāo)簽
plt.ylabel('播放次數(shù)', fontsize=24) # 設(shè)置y軸標(biāo)簽
plt.title('視頻周播放量數(shù)據(jù)—宣一名', fontsize=35, pad=45) # 設(shè)置標(biāo)題
plt.plot(x,y, label = "播放次數(shù)",color='r',marker='s' ) # 繪制圖形
plt.legend(fontsize=20)
plt.show() # 展示圖形,在Jupyter中,可省略本行c

散點圖
import matplotlib.pyplot as plt # 調(diào)用畫圖庫
plt.rcParams['font.sans-serif'] = ['SimHei'] # 設(shè)置成可以顯示中文,字體為黑體
plt.figure(figsize=(12, 8)) # 調(diào)整圖片尺寸
x = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
y = [401,632,453,894,775,646,1207]
y1 = [20,33,27,45,39,24,64]
plt.tick_params(labelsize=21) # 設(shè)置坐標(biāo)軸刻度的字體大小為 21
plt.xlabel('日期', fontsize=21, labelpad=20) # 設(shè)置 x 軸名稱
plt.ylabel('播放次數(shù)', fontsize=21,labelpad=20) # 設(shè)置 y 軸名稱
plt.title('每日播放量與新增粉絲量-宣一名', fontsize=27, pad=45) # 設(shè)置標(biāo)題
plt.grid( color = 'c', linewidth = 2, linestyle = ':', alpha = 0.3) # 設(shè)置網(wǎng)格,顏色、線寬、樣式、透明度
plt.scatter(x,y, marker = '*', c = 'r', s = 200,label="播放次數(shù)") # 繪制散點圖, 設(shè)置散點樣式
plt.legend()
plt.twinx() #添加右側(cè) y 軸,實際上是又畫了一個折線圖,和柱狀圖共享 x 軸
plt.tick_params(labelsize=21) # 設(shè)置坐標(biāo)軸刻度的字體大小
plt.ylim(0,40)
plt.ylabel('粉絲增長數(shù)', fontsize=24,labelpad=20) # 設(shè)置 y 軸標(biāo)簽
plt.scatter(x,y1, marker = 'H', c = 'b', s = 200,label="新增粉絲")
plt.legend()
plt.show()

二、Pyecharts繪圖
熱力圖
from pyecharts import options as opts # 調(diào)用圖表配置選項庫
from pyecharts.charts import HeatMap # 調(diào)用畫圖庫
課程安排數(shù)據(jù) =[[0, 3, 21], [1, 3, 30], [2, 3,10], [3, 3, 41], [4, 3, 28], [5, 3, 50], [6, 3, 254],
[0, 2, 82], [1, 2, 110], [2, 2, 105], [3, 2,235], [4, 2, 212], [5, 2, 223], [6, 2, 799],
[0, 1, 101], [1, 1, 230], [2, 1, 218 ], [3, 1, 407], [4, 1, 262], [5, 1, 225], [6, 1, 377],
[0, 0, 245], [1, 0, 331], [2, 0, 103], [3, 0, 306], [4, 0, 499], [5, 0, 227], [6, 0, 99] ]# 設(shè)置數(shù)據(jù)
熱力圖橫坐標(biāo) = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] # x軸坐標(biāo)數(shù)據(jù)
熱力圖縱坐標(biāo) = ['深夜','晚上','下午','上午'] # y軸坐標(biāo)數(shù)據(jù)
寬3='410px' # 設(shè)置圖片寬度高度變量
高3='250px'
熱力圖 = (
HeatMap(init_opts=opts.InitOpts(width=寬3, height=高3, chart_id=3)) # 繪圖,設(shè)置圖片大小、圖表id
.add_xaxis(熱力圖橫坐標(biāo)) # 設(shè)置x軸坐標(biāo)名
.add_yaxis("", 熱力圖縱坐標(biāo), 課程安排數(shù)據(jù), # 設(shè)置y軸坐標(biāo)名,添加數(shù)據(jù)
label_opts=opts.LabelOpts(color="white", # 標(biāo)簽字體顏色
font_size=13, # 字體大小
position="inside"), # 位置
itemstyle_opts=opts.ItemStyleOpts(border_color='white', # 邊界線顏色
border_width=3)) # 邊界線寬度
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(max_=799,is_show=False), # 設(shè)置視覺映射配置項,最大值為600
xaxis_opts = opts.AxisOpts(
axislabel_opts = opts.LabelOpts(font_size = 13, # 坐標(biāo)軸字體大小
color='black'), # 坐標(biāo)軸字體顏色
axisline_opts = opts.AxisLineOpts(
linestyle_opts=opts.LineStyleOpts(
color='white', # 坐標(biāo)軸線顏色
width=3))), # 坐標(biāo)軸線寬度
yaxis_opts = opts.AxisOpts(
axislabel_opts = opts.LabelOpts(font_size = 13, # 坐標(biāo)軸字體大小
color='black'), # 坐標(biāo)軸字體顏色
axisline_opts = opts.AxisLineOpts(
linestyle_opts=opts.LineStyleOpts(
color='white', # 坐標(biāo)軸線顏色
width=3))), # 坐標(biāo)軸線寬度 width=3))), # 坐標(biāo)軸線寬度
title_opts = opts.TitleOpts(
title='課 程 安 排 熱 力 圖-宣一名', # 設(shè)置標(biāo)題
title_textstyle_opts=opts.TextStyleOpts(font_size = 20, # 標(biāo)題字體大小
color="black"), # 標(biāo)題顏色
pos_left = 'center',pos_top='10%'))) # 設(shè)置居中
# 將圖表作為函數(shù)返回值
熱力圖.render_notebook()

散點圖
from pyecharts.charts import Scatter # 調(diào)用畫圖庫
import pyecharts.options as opts # 調(diào)用圖表配置選項庫
x = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
y = [401,632,453,894,775,646,1207]
y1 = [20,33,27,45,39,24,64]
散點圖 =(
Scatter(init_opts=opts.InitOpts(width="800px", height="600px")) # 定義散點圖,設(shè)置圖片大小
.add_xaxis(x) # 添加x軸數(shù)據(jù)
.add_yaxis('每日播放量', y, # 添加y軸數(shù)據(jù)
symbol_size = 20, # 設(shè)置散點大小
symbol = 'triangle', # 設(shè)置散點為三角形
color = 'blue', # 設(shè)置綠色
) # 取消自動注釋
.add_yaxis("粉絲數(shù)",y1)
.set_global_opts(
title_opts = opts.TitleOpts(title='播放量與粉絲增長情況-宣一名', # 設(shè)置標(biāo)題
title_textstyle_opts=opts.TextStyleOpts(font_size = 15,color="black"), # 設(shè)置字體大小
pos_left = 'center'), # 設(shè)置居中
legend_opts=(opts.LegendOpts(pos_left="75%")),
yaxis_opts=opts.AxisOpts(name="播放量",splitline_opts = opts.SplitLineOpts(is_show=True, # 顯示y軸網(wǎng)格線
linestyle_opts= opts.LineStyleOpts(
width= 3, # 網(wǎng)格寬度為3
opacity=0.9, # 透明度90%
type_='dotted')),
name_textstyle_opts=opts.TextStyleOpts(color="black")),文章來源:http://www.zghlxwxcb.cn/news/detail-450804.html
xaxis_opts=opts.Axi文章來源地址http://www.zghlxwxcb.cn/news/detail-450804.html
到了這里,關(guān)于運用pyecharts制作可視化大屏(代碼展示及效果圖-動圖)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!