{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6-final"
},
"orig_nbformat": 2,
"kernelspec": {
"name": "python_defaultSpec_1600778749683",
"display_name": "Python 3.6.6 64-bit ('win': conda)"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"source": [
"# 單因子變異數分析 - Python實戰:如何決定多廣告的優化策略?"
],
"cell_type": "markdown",
"metadata": {}
},
{
"source": [
"#### 作者:徐子皓(臺灣行銷研究特邀作者)\n",
"#### 完整文章介紹鏈接:https://medium.com/p/7c99643043b0/"
],
"cell_type": "markdown",
"metadata": {}
},
{
"source": [
"## 一、事前檢驗"
],
"cell_type": "markdown",
"metadata": {}
},
{
"source": [
"### 1. shapiro常態性檢定"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "ShapiroResult(statistic=0.9915865659713745, pvalue=0.6819638013839722)"
},
"metadata": {},
"execution_count": 7
}
],
"source": [
"import scipy.stats as st\n",
"st.shapiro(alist)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "ShapiroResult(statistic=0.9929247498512268, pvalue=0.805463969707489)"
},
"metadata": {},
"execution_count": 8
}
],
"source": [
"st.shapiro(blist)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "ShapiroResult(statistic=0.9802003502845764, pvalue=0.07433854043483734)"
},
"metadata": {},
"execution_count": 9
}
],
"source": [
"st.shapiro(clist)"
]
},
{
"source": [
"### 2. levene同質性檢定"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "LeveneResult(statistic=0.6891243668404422, pvalue=0.5026819827621525)"
},
"metadata": {},
"execution_count": 10
}
],
"source": [
"st.levene(alist, blist, clist, center='mean')"
]
},
{
"source": [
"## 二、變異數分析"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "0.0955577857122512"
},
"metadata": {},
"execution_count": 11
}
],
"source": [
"f_value, p_value = st.f_oneway(alist, blist, clist)\n",
"p_value"
]
},
{
"source": [
"## 三、事後檢定"
],
"cell_type": "markdown",
"metadata": {}
},
{
"source": [
"### 1. pairwise_tukey事後檢定"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": " A B mean(A) mean(B) diff se T p-tukey \\\n0 廣告1 廣告2 17.135167 15.592417 1.54275 0.781281 1.974642 0.118914 \n1 廣告1 廣告3 17.135167 15.748167 1.38700 0.781281 1.775290 0.178294 \n2 廣告2 廣告3 15.592417 15.748167 -0.15575 0.781281 -0.199352 0.900000 \n\n hedges \n0 0.254121 \n1 0.228466 \n2 -0.025655 ",
"text/html": "
\n\n
\n \n \n | \n A | \n B | \n mean(A) | \n mean(B) | \n diff | \n se | \n T | \n p-tukey | \n hedges | \n
\n \n \n \n 0 | \n 廣告1 | \n 廣告2 | \n 17.135167 | \n 15.592417 | \n 1.54275 | \n 0.781281 | \n 1.974642 | \n 0.118914 | \n 0.254121 | \n
\n \n 1 | \n 廣告1 | \n 廣告3 | \n 17.135167 | \n 15.748167 | \n 1.38700 | \n 0.781281 | \n 1.775290 | \n 0.178294 | \n 0.228466 | \n
\n \n 2 | \n 廣告2 | \n 廣告3 | \n 15.592417 | \n 15.748167 | \n -0.15575 | \n 0.781281 | \n -0.199352 | \n 0.900000 | \n -0.025655 | \n
\n \n
\n
"
},
"metadata": {},
"execution_count": 13
}
],
"source": [
"from pingouin import pairwise_tukey\n",
"m_comp = pairwise_tukey(data=data, dv='消費金額', between='廣告')\n",
"m_comp"
]
},
{
"source": [
"### 2. 整理成可參考報表"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": " A B diff se\n0 廣告1 廣告2 1.54275 0.781281\n1 廣告1 廣告3 1.38700 0.781281\n2 廣告2 廣告3 -0.15575 0.781281",
"text/html": "\n\n
\n \n \n | \n A | \n B | \n diff | \n se | \n
\n \n \n \n 0 | \n 廣告1 | \n 廣告2 | \n 1.54275 | \n 0.781281 | \n
\n \n 1 | \n 廣告1 | \n 廣告3 | \n 1.38700 | \n 0.781281 | \n
\n \n 2 | \n 廣告2 | \n 廣告3 | \n -0.15575 | \n 0.781281 | \n
\n \n
\n
"
},
"metadata": {},
"execution_count": 15
}
],
"source": [
"table = m_comp.drop(columns = ['mean(A)', 'mean(B)', 'T', 'p-tukey', 'hedges'])\n",
"table"
]
},
{
"source": [
"## 四、進階資料處理"
],
"cell_type": "markdown",
"metadata": {}
},
{
"source": [
"### 1. 計算反轉資料"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"# 「A」欄反轉資料\n",
"add_A = table['B'].tolist()\n",
"# 「B」欄反轉資料\n",
"add_B = table['A'].tolist()\n",
"# 「diff」欄反轉資料\n",
"diff = (table['diff'] - 2 * table['diff']).tolist()\n",
"# 「se」欄反轉資料\n",
"se = table['se'].tolist()\n",
"# 將反轉資料合併\n",
"table2 = pd.DataFrame(zip(add_A, add_B, diff, se), columns = ['A', 'B', 'diff', 'se'])"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": " A B diff se\n0 廣告2 廣告1 -1.54275 0.781281\n1 廣告3 廣告1 -1.38700 0.781281\n2 廣告3 廣告2 0.15575 0.781281",
"text/html": "\n\n
\n \n \n | \n A | \n B | \n diff | \n se | \n
\n \n \n \n 0 | \n 廣告2 | \n 廣告1 | \n -1.54275 | \n 0.781281 | \n
\n \n 1 | \n 廣告3 | \n 廣告1 | \n -1.38700 | \n 0.781281 | \n
\n \n 2 | \n 廣告3 | \n 廣告2 | \n 0.15575 | \n 0.781281 | \n
\n \n
\n
"
},
"metadata": {},
"execution_count": 18
}
],
"source": [
"table2"
]
},
{
"source": [
"### 2. 將資料整併成new_table"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": " A B diff se\n0 廣告1 廣告2 1.54275 0.781281\n1 廣告1 廣告3 1.38700 0.781281\n2 廣告2 廣告3 -0.15575 0.781281\n3 廣告2 廣告1 -1.54275 0.781281\n4 廣告3 廣告1 -1.38700 0.781281\n5 廣告3 廣告2 0.15575 0.781281",
"text/html": "\n\n
\n \n \n | \n A | \n B | \n diff | \n se | \n
\n \n \n \n 0 | \n 廣告1 | \n 廣告2 | \n 1.54275 | \n 0.781281 | \n
\n \n 1 | \n 廣告1 | \n 廣告3 | \n 1.38700 | \n 0.781281 | \n
\n \n 2 | \n 廣告2 | \n 廣告3 | \n -0.15575 | \n 0.781281 | \n
\n \n 3 | \n 廣告2 | \n 廣告1 | \n -1.54275 | \n 0.781281 | \n
\n \n 4 | \n 廣告3 | \n 廣告1 | \n -1.38700 | \n 0.781281 | \n
\n \n 5 | \n 廣告3 | \n 廣告2 | \n 0.15575 | \n 0.781281 | \n
\n \n
\n
"
},
"metadata": {},
"execution_count": 19
}
],
"source": [
"new_table = pd.concat([table, table2], ignore_index=True)\n",
"new_table"
]
},
{
"source": [
"### 3. 計算資料上下界"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": " A B diff se 上界 下界\n0 廣告1 廣告2 1.54275 0.781281 3.074061 0.011439\n1 廣告1 廣告3 1.38700 0.781281 2.918311 -0.144311\n2 廣告2 廣告3 -0.15575 0.781281 1.375561 -1.687061\n3 廣告2 廣告1 -1.54275 0.781281 -0.011439 -3.074061\n4 廣告3 廣告1 -1.38700 0.781281 0.144311 -2.918311\n5 廣告3 廣告2 0.15575 0.781281 1.687061 -1.375561",
"text/html": "\n\n
\n \n \n | \n A | \n B | \n diff | \n se | \n 上界 | \n 下界 | \n
\n \n \n \n 0 | \n 廣告1 | \n 廣告2 | \n 1.54275 | \n 0.781281 | \n 3.074061 | \n 0.011439 | \n
\n \n 1 | \n 廣告1 | \n 廣告3 | \n 1.38700 | \n 0.781281 | \n 2.918311 | \n -0.144311 | \n
\n \n 2 | \n 廣告2 | \n 廣告3 | \n -0.15575 | \n 0.781281 | \n 1.375561 | \n -1.687061 | \n
\n \n 3 | \n 廣告2 | \n 廣告1 | \n -1.54275 | \n 0.781281 | \n -0.011439 | \n -3.074061 | \n
\n \n 4 | \n 廣告3 | \n 廣告1 | \n -1.38700 | \n 0.781281 | \n 0.144311 | \n -2.918311 | \n
\n \n 5 | \n 廣告3 | \n 廣告2 | \n 0.15575 | \n 0.781281 | \n 1.687061 | \n -1.375561 | \n
\n \n
\n
"
},
"metadata": {},
"execution_count": 20
}
],
"source": [
"new_table['上界'] = new_table['diff'] + new_table['se']*1.96\n",
"new_table['下界'] = new_table['diff'] - new_table['se']*1.96\n",
"new_table"
]
},
{
"source": [
"### 4. np.sign用法示意"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "1"
},
"metadata": {},
"execution_count": 21
}
],
"source": [
"import numpy as np\n",
"np.sign(12)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "-1.0"
},
"metadata": {},
"execution_count": 22
}
],
"source": [
"np.sign(-5.6)"
]
},
{
"source": [
"### 5. 判斷資料是否顯著"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"justice = []\n",
"for i in range(0,new_table.shape[0]):\n",
" a = np.sign(new_table.iloc[i,4]) # 上界正負數判斷\n",
" b = np.sign(new_table.iloc[i,5]) # 下界正負數判斷\n",
" if a == b:\n",
" justice.append('Yes')\n",
" else:\n",
" justice.append('No')"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "['Yes', 'No', 'No', 'Yes', 'No', 'No']"
},
"metadata": {},
"execution_count": 24
}
],
"source": [
"justice"
]
},
{
"source": [
"### 6. 將「是否顯著」結果回存至new_table中"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": " A B diff se 上界 下界 是否顯著\n0 廣告1 廣告2 1.54275 0.781281 3.074061 0.011439 Yes\n1 廣告1 廣告3 1.38700 0.781281 2.918311 -0.144311 No\n2 廣告2 廣告3 -0.15575 0.781281 1.375561 -1.687061 No\n3 廣告2 廣告1 -1.54275 0.781281 -0.011439 -3.074061 Yes\n4 廣告3 廣告1 -1.38700 0.781281 0.144311 -2.918311 No\n5 廣告3 廣告2 0.15575 0.781281 1.687061 -1.375561 No",
"text/html": "\n\n
\n \n \n | \n A | \n B | \n diff | \n se | \n 上界 | \n 下界 | \n 是否顯著 | \n
\n \n \n \n 0 | \n 廣告1 | \n 廣告2 | \n 1.54275 | \n 0.781281 | \n 3.074061 | \n 0.011439 | \n Yes | \n
\n \n 1 | \n 廣告1 | \n 廣告3 | \n 1.38700 | \n 0.781281 | \n 2.918311 | \n -0.144311 | \n No | \n
\n \n 2 | \n 廣告2 | \n 廣告3 | \n -0.15575 | \n 0.781281 | \n 1.375561 | \n -1.687061 | \n No | \n
\n \n 3 | \n 廣告2 | \n 廣告1 | \n -1.54275 | \n 0.781281 | \n -0.011439 | \n -3.074061 | \n Yes | \n
\n \n 4 | \n 廣告3 | \n 廣告1 | \n -1.38700 | \n 0.781281 | \n 0.144311 | \n -2.918311 | \n No | \n
\n \n 5 | \n 廣告3 | \n 廣告2 | \n 0.15575 | \n 0.781281 | \n 1.687061 | \n -1.375561 | \n No | \n
\n \n
\n
"
},
"metadata": {},
"execution_count": 25
}
],
"source": [
"new_table['是否顯著'] = justice\n",
"new_table"
]
},
{
"source": [
"## 五、資料視覺化\t"
],
"cell_type": "markdown",
"metadata": {}
},
{
"source": [
"### 1. 基本資料輸入"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"import plotly.offline as py\n",
"import plotly.graph_objects as go\n",
"fig = go.Figure()\n",
"for i in range(0, new_table.shape[0]):\n",
" if new_table.iloc[i,6] == 'Yes':\n",
" color = 'firebrick'\n",
" name = '顯著'\n",
" else:\n",
" color = 'green'\n",
" name = '不顯著'\n",
" fig.add_trace(go.Scatter(\n",
" x = [new_table.iloc[i,5], new_table.iloc[i,2], new_table.iloc[i,4]],\n",
" y = [new_table.iloc[i,0] + '-' + new_table.iloc[i,1], new_table.iloc[i,0] + '-' + new_table.iloc[i,1], new_table.iloc[i,0] + '-' + new_table.iloc[i,1]],\n",
" mode = \"lines+markers\",\n",
" textfont=dict(\n",
" family=\"sans serif\",\n",
" size=16,\n",
" color=color), \n",
" line=dict(color=color, width=2),\n",
" name = name,\n",
" legendgroup = name,\n",
" ))"
]
},
{
"source": [
"### 2. 設定佈景主題"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"legendgroup": "顯著",
"line": {
"color": "firebrick",
"width": 2
},
"mode": "lines+markers",
"name": "顯著",
"textfont": {
"color": "firebrick",
"family": "sans serif",
"size": 16
},
"type": "scatter",
"x": [
0.011439440747863072,
1.5427500000000105,
3.0740605592521577
],
"y": [
"廣告1-廣告2",
"廣告1-廣告2",
"廣告1-廣告2"
]
},
{
"legendgroup": "不顯著",
"line": {
"color": "green",
"width": 2
},
"mode": "lines+markers",
"name": "不顯著",
"textfont": {
"color": "green",
"family": "sans serif",
"size": 16
},
"type": "scatter",
"x": [
-0.14431055925213632,
1.3870000000000111,
2.9183105592521583
],
"y": [
"廣告1-廣告3",
"廣告1-廣告3",
"廣告1-廣告3"
]
},
{
"legendgroup": "不顯著",
"line": {
"color": "green",
"width": 2
},
"mode": "lines+markers",
"name": "不顯著",
"textfont": {
"color": "green",
"family": "sans serif",
"size": 16
},
"type": "scatter",
"x": [
-1.6870605592521468,
-0.1557499999999994,
1.375560559252148
],
"y": [
"廣告2-廣告3",
"廣告2-廣告3",
"廣告2-廣告3"
]
},
{
"legendgroup": "顯著",
"line": {
"color": "firebrick",
"width": 2
},
"mode": "lines+markers",
"name": "顯著",
"textfont": {
"color": "firebrick",
"family": "sans serif",
"size": 16
},
"type": "scatter",
"x": [
-3.0740605592521577,
-1.5427500000000105,
-0.011439440747863072
],
"y": [
"廣告2-廣告1",
"廣告2-廣告1",
"廣告2-廣告1"
]
},
{
"legendgroup": "不顯著",
"line": {
"color": "green",
"width": 2
},
"mode": "lines+markers",
"name": "不顯著",
"textfont": {
"color": "green",
"family": "sans serif",
"size": 16
},
"type": "scatter",
"x": [
-2.9183105592521583,
-1.3870000000000111,
0.14431055925213632
],
"y": [
"廣告3-廣告1",
"廣告3-廣告1",
"廣告3-廣告1"
]
},
{
"legendgroup": "不顯著",
"line": {
"color": "green",
"width": 2
},
"mode": "lines+markers",
"name": "不顯著",
"textfont": {
"color": "green",
"family": "sans serif",
"size": 16
},
"type": "scatter",
"x": [
-1.375560559252148,
0.1557499999999994,
1.6870605592521468
],
"y": [
"廣告3-廣告2",
"廣告3-廣告2",
"廣告3-廣告2"
]
}
],
"layout": {
"boxmode": "group",
"font": {
"color": "lightslategrey",
"family": "Courier New, monospace",
"size": 20
},
"height": 960,
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "#E5ECF6",
"width": 0.5
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "white",
"linecolor": "white",
"minorgridcolor": "white",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "#E5ECF6",
"showlakes": true,
"showland": true,
"subunitcolor": "white"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "#E5ECF6",
"polar": {
"angularaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"radialaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"yaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
},
"zaxis": {
"backgroundcolor": "#E5ECF6",
"gridcolor": "white",
"gridwidth": 2,
"linecolor": "white",
"showbackground": true,
"ticks": "",
"zerolinecolor": "white"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"baxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
},
"bgcolor": "#E5ECF6",
"caxis": {
"gridcolor": "white",
"linecolor": "white",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "white",
"linecolor": "white",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "white",
"zerolinewidth": 2
}
}
},
"title": {
"text": "One-Way ANOVA 廣告效益分析",
"x": 0.5,
"xanchor": "center",
"y": 0.95
},
"width": 1800
}
}
},
"metadata": {}
}
],
"source": [
"fig.update_layout(\n",
" title={\n",
" 'text': \"One-Way ANOVA 廣告效益分析\",\n",
" 'y':0.95,\n",
" 'x':0.5,\n",
" 'xanchor': 'center',},\n",
" width=1800,\n",
" height=960,\n",
" boxmode='group',\n",
" font=dict(\n",
" family=\"Courier New, monospace\",\n",
" size=20,\n",
" color=\"lightslategrey\"\n",
" )\n",
" ) "
]
},
{
"source": [
"### 3. 將產出圖片另存"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 另存互動式網頁\n",
"py.plot(fig, filename='One-Way ANOVA 廣告效益分析', auto_open=True)\n",
"# 另存.png圖檔\n",
"fig.write_image(\"C:/Users/user/Desktop/單因子變異數分析1.5/One-Way ANOVA 廣告效益分析.png\")"
]
}
]
}