<!-- <!DOCTYPE html>
<html>
<head><title>視覺映射和圖例</title><meta charset="utf-8"><script src="echarts.js"></script>
</head>
<body>
<div style="width: 600px;height:400px;">
<script type="text/javascript">var myChart = echarts.init(document.getElementById('main'));var option = {legend: {// Try 'horizontal'orient: 'vertical',right: 10,top: 20,bottom: 20,type: 'scroll',backgroundColor: '#000',textStyle:{color:'#FFF',},icon: 'square',},dataset: {source: [['product', '2015', '2016', '2017', '2018', '2019', ],['Matcha Latte', 43.3, 85.8, 93.7, 43.3, 85.8, 93.7, 72.4, 53.9, 39.1],['Milk Tea', 83.1, 73.4, 55.1, 83.1, 73.4, 55.1, 72.4, 53.9, 39.1],['Cheese Cocoa', 86.4, 65.2, 82.5, 86.4, 65.2, 82.5, 72.4, 53.9, 39.1],['Walnut Brownie', 72.4, 53.9, 39.1, 72.4, 53.9, 39.1, 72.4, 53.9, 39.1]]},xAxis: { type: 'category' },yAxis: {},series: [{ type: 'line' }, { type: 'line' }, { type: 'line' }, { type: 'line' }, { type: 'line' }, { type: 'line' },]};myChart.setOption(option);</script></div>
</body>
</html>--><!DOCTYPE html>
<html><head><meta charset="utf-8" /><!-- 引入剛剛下載的 ECharts 文件 --><script src="echarts.js"></script></head><body><div id="main" style="width: 600px;height:400px;"> <script type="text/javascript">// 基于準備好的dom,初始化echarts實例var myChart = echarts.init(document.getElementById('main'),'purple-passion');// 指定圖表的配置項和數據var option = {legend: {// Try 'horizontal'orient: 'vertical',right: 10,top: 20,bottom: 20,type: 'scroll',backgroundColor: '#000',textStyle:{color:'#FFF',},icon: 'square',},dataset: {source: [['product', '2015', '2016', '2017', '2018', '2019', ],['Matcha Latte', 43.3, 85.8, 93.7, 43.3, 85.8, 93.7, 72.4, 53.9, 39.1],['Milk Tea', 83.1, 73.4, 55.1, 83.1, 73.4, 55.1, 72.4, 53.9, 39.1],['Cheese Cocoa', 86.4, 65.2, 82.5, 86.4, 65.2, 82.5, 72.4, 53.9, 39.1],['Walnut Brownie', 72.4, 53.9, 39.1, 72.4, 53.9, 39.1, 72.4, 53.9, 39.1]]},xAxis: { type: 'category' },yAxis: {},series: [{ type: 'line' }, { type: 'line' }, { type: 'line' }, { type: 'line' }, { type: 'line' }, { type: 'line' },]};// 使用剛指定的配置項和數據顯示圖表。myChart.setOption(option);</script></div></body>
</html>
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>多圖表示例</title><!-- 引入 ECharts 文件 --><script src="echarts.js"></script></head><body><!-- 柱狀圖容器 --><div id="barChart" style="width: 400px; height: 300px; float: left;"></div><!-- 條形圖容器 --><div id="barHorizontalChart" style="width: 400px; height: 300px; float: left;"></div><!-- 折線圖容器 --><div id="lineChart" style="width: 400px; height: 300px; float: left;"></div><!-- 餅圖容器 --><div id="pieChart" style="width: 400px; height: 300px; float: left;"></div><!-- 雷達圖容器 --><div id="radarChart" style="width: 400px; height: 300px; float: left;"></div><script type="text/javascript">var barChart = echarts.init(document.getElementById('barChart'));var barHorizontalChart = echarts.init(document.getElementById('barHorizontalChart'));var lineChart = echarts.init(document.getElementById('lineChart'));var pieChart = echarts.init(document.getElementById('pieChart'));var radarChart = echarts.init(document.getElementById('radarChart')); // 柱狀圖配置項 var barOption = {xAxis: { type: 'category',data: ['A', 'B', 'C', 'D', 'E', 'F'] },yAxis: { type: 'value' }, series: [{ data: [210, 320, 280, 330, 350, 420], type: 'bar' }] }; // 條形圖配置項var barHorizontalOption = {yAxis: { type: 'category', data: ['A', 'B', 'C', 'D', 'E', 'F'] }, xAxis: { type: 'value' }, series: [{ data: [210, 320, 280, 330, 350, 420], type: 'bar' }] };// 折線圖配置項var lineOption = {xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, series: [{ data: [120, 200, 150, 80, 70, 110, 130], type: 'line' }] };// 餅圖配置項var pieOption = {series: [{ data: [ {value: 335, name: 'A'}, {value: 310, name: 'B'}, {value: 234, name: 'C'}, {value: 135, name: 'D'}, {value: 1548, name: 'E'} ], type: 'pie' }] };// 雷達圖配置項var radarOption = { radar: { indicator: [ {name: 'A', max: 6500}, {name: 'B', max: 16000}, {name: 'C', max: 30000}, {name: 'D', max: 38000}, {name: 'E', max: 52000} ] }, series: [{ type: 'radar', data : [ { value : [4300, 10000, 28000, 35000, 50000], name : 'Data' } ] }] }; barChart.setOption(barOption); barHorizontalChart.setOption(barHorizontalOption); lineChart.setOption(lineOption); pieChart.setOption(pieOption); radarChart.setOption(radarOption);</script></body>
</html>
import matplotlib.pyplot as plt# 定義 x 軸數據
x = [0, 1, 2, 3, 4]# 定義 y 軸數據
y = [0, 1, 2, 3, 4]# 繪制圖形
plt.plot(x, y)# 顯示圖形
plt.show()import matplotlib.pyplot as plt# x 軸數據
x = [1, 2, 3, 4, 5]
# y 軸數據
y = [2, 4, 6, 8, 10]# 繪制折線圖
plt.plot(x, y)# 添加圖表標題和坐標軸標簽
plt.title('折線圖示例')
plt.xlabel('X 軸')
plt.ylabel('Y 軸')# 顯示圖形
plt.show()import matplotlib.pyplot as plt# x 軸數據
x = [1, 2, 3, 4, 5]
# y 軸數據
y = [2, 4, 6, 8, 10]
# 繪制折線圖并設置線條樣式為虛線
plt.plot(x, y, linestyle='--')
# 添加圖表標題和坐標軸標簽
plt.title('折線圖示例')
plt.xlabel('X 軸')
plt.ylabel('Y 軸')
# 顯示圖形
plt.show()import matplotlib.pyplot as plt# x 軸數據
x = [1, 2, 3, 4, 5]
# y 軸數據
y = [2, 4, 6, 8, 10]# 設置 x 軸刻度
plt.xticks([1, 2, 3, 4, 5], ['A', 'B', 'C', 'D', 'E'])# 繪制折線圖
plt.plot(x, y)# 添加圖表標題和坐標軸標簽
plt.title('折線圖示例')
plt.xlabel('自定義 X 軸')
plt.ylabel('Y 軸')# 顯示圖形
plt.show()import matplotlib.pyplot as plt# x 軸數據
x = [1, 2, 3, 4, 5]
# y 軸數據
y = [2, 4, 6, 8, 10]# 設置 x 軸字體大小和顏色
plt.xticks(fontsize=16, color='red')
# 設置 y 軸字體大小和顏色
plt.yticks(fontsize=16, color='red')# 繪制折線圖
plt.plot(x, y)# 添加圖表標題和坐標軸標簽
plt.title('折線圖示例')
plt.xlabel('X 軸')
plt.ylabel('Y 軸')# 顯示圖形
plt.show()import matplotlib.pyplot as plt# x 軸數據
x = [1, 2, 3, 4, 5]
# y1 軸數據
y1 = [2, 4, 6, 8, 10]
# y2 軸數據
y2 = [4, 6, 8, 10, 12]# 繪制第一個折線圖
plt.subplot(211)
plt.plot(x, y1)
plt.title('折線圖 1')# 繪制第二個折線圖
plt.subplot(212)
plt.plot(x, y2)
plt.title('折線圖 2')# 設置子圖之間的間距
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.5, hspace=0.5)# 顯示圖形
plt.show()
import matplotlib.pyplot as plt
import numpy as np# 生成隨機數據
x = np.arange(1, 11)
print(x)
y_line = np.random.randint(1, 10, size=10)
print(y_line)
y_bar = np.random.randint(1, 10, size=10)
y_barh = np.random.randint(1, 10, size=10)
theta = np.linspace(0, 2*np.pi, 10)
y_radar = np.random.randint(1, 10, size=10)
print(y_bar,y_barh,y_radar)# 折線圖
plt.figure(figsize=(8, 6)) #創建圖像窗口,大小為8*6英寸
plt.plot(x, y_line, marker='o', linestyle='-', color='b') #繪制折線圖,圓形標記,實線,藍色
plt.title('折線圖')
plt.xlabel('X軸')
plt.ylabel('Y軸')
plt.grid(True) #顯示網格線
plt.show()#柱狀圖
# 創建一個圖像窗口,并設置大小為8x6英寸
plt.figure(figsize=(8, 6))
# 繪制柱狀圖,x為橫坐標數據,y_bar為縱坐標數據,顏色為綠色,透明度為0.7
plt.bar(x, y_bar, color='g', alpha=0.7)
# 設置圖像標題
plt.title('柱狀圖')
# 設置橫坐標標簽
plt.xlabel('X軸')
# 設置縱坐標標簽
plt.ylabel('Y軸')
# 啟用縱向網格線
plt.grid(axis='y')
# 顯示圖像
plt.show()#條形圖
# 創建一個圖像窗口,并設置大小為8x6英寸
plt.figure(figsize=(8, 6))
# 繪制條形圖,x為縱坐標數據,y_barh為橫坐標數據,顏色為紅色,透明度為0.7
plt.barh(x, y_barh, color='r', alpha=0.7)
# 設置圖像標題
plt.title('條形圖')
# 設置橫坐標標簽
plt.xlabel('X軸')
# 設置縱坐標標簽
plt.ylabel('Y軸')
# 啟用橫向網格線
plt.grid(axis='x')
# 顯示圖像
plt.show()#雷達圖# 創建一個圖像窗口,并設置大小為8x6英寸
plt.figure(figsize=(8, 6))
# 創建一個極坐標子圖
ax = plt.subplot(111, polar=True)
# 繪制雷達圖,theta為角度數據,y_radar為雷達圖的值,使用圓形標記
ax.plot(theta, y_radar, marker='o')
# 填充雷達圖內部,顏色為藍色,透明度為0.1
ax.fill(theta, y_radar, 'b', alpha=0.1)
# 設置圖像標題
plt.title('雷達圖')
# 顯示圖像
plt.show()
import matplotlib.pyplot as plt
# 數據
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
sizes = [20, 50, 80, 150, 300]
# 氣泡大小
# 繪制氣泡圖
plt.scatter(x, y, s=sizes, alpha=0.6, c='blue', label='氣泡')
# 添加標簽和標題
plt.xlabel('X 軸')
plt.ylabel('Y 軸')
plt.title('簡單的氣泡圖')
# 顯示圖例
plt.legend()
# 顯示圖表
plt.show()import matplotlib.pyplot as plt
import numpy as np
# 定義數據
categories = ['類別1', '類別2', '類別3']
group1 = [3, 5, 2]
group2 = [4, 2, 7]
group3 = [6, 8, 3]
# 定義x軸的索引位置
x = np.arange(len(categories))
# 創建堆積柱形圖
plt.bar(x, group1, label='組1')
plt.bar(x, group2, bottom=group1, label='組2')
plt.bar(x, group3, bottom=np.array(group1) + np.array(group2), label='組3')
# 添加x軸的標簽
plt.xticks(x, categories)
# 添加圖例
plt.legend()
# 添加標題和軸標簽
plt.title('堆積柱形圖')
plt.xlabel('類別')
plt.ylabel('數量')
# 顯示圖表
plt.show()import matplotlib.pyplot as plt# 數據
x = [20,21,22,23]
y1 = [10, 20, 15, 25]
y2 = [15, 25, 20, 30]# 繪制簇狀柱形圖
width = 0.35
plt.bar(x, y1, width, label='Group 1')
plt.bar([i + 0.35 for i in x], y2, width, label='Group 2')
plt.xlabel('X 軸')
plt.ylabel('Y 軸')
plt.title('簇狀柱形圖')
plt.xticks(x)
plt.legend()
plt.show()import matplotlib.pyplot as plt
import numpy as np
# 定義數據
years = np.array([2016, 2017, 2018, 2019, 2020])
category1 = np.array([3, 4, 6, 7, 9])
category2 = np.array([1, 3, 4, 3, 6])
category3 = np.array([2, 2, 3, 4, 5])
# 繪制堆積折線圖
plt.stackplot(years, category1, category2, category3,labels=['類別1', '類別2', '類別3'],colors=['#FFDDC1', '#FFABAB', '#FF6F61'])
# 添加圖例
plt.legend(loc='upper left')
# 添加標題和軸標簽
plt.title('堆積折線圖示例')
plt.xlabel('年份')
plt.ylabel('數量')
# 顯示圖表
plt.show()