veghdev commited on
Commit
0147ea5
1 Parent(s): 14d0b38

Update ipyvizzu_demo.ipynb

Browse files
Files changed (1) hide show
  1. ipyvizzu_demo.ipynb +67 -98
ipyvizzu_demo.ipynb CHANGED
@@ -1,121 +1,90 @@
1
  {
2
  "cells": [
3
- {
4
- "cell_type": "raw",
5
- "id": "41022af5",
6
- "metadata": {},
7
- "source": [
8
- "---\n",
9
- "title: ipyvizzu demo\n",
10
- "description: ipyvizzu mercury demo\n",
11
- "show-code: False\n",
12
- "params:\n",
13
- "params:\n",
14
- " gender:\n",
15
- " input: select\n",
16
- " label: select the gender\n",
17
- " choices: [male, female]\n",
18
- " multi: False\n",
19
- "---"
20
- ]
21
- },
22
- {
23
- "cell_type": "code",
24
- "execution_count": null,
25
- "id": "bf9e62cb",
26
- "metadata": {},
27
- "outputs": [],
28
- "source": [
29
- "# configure default value\n",
30
- "\n",
31
- "gender = 'male'\n"
32
- ]
33
- },
34
  {
35
  "cell_type": "code",
36
  "execution_count": null,
37
- "id": "1226e7e9",
38
  "metadata": {},
39
  "outputs": [],
40
  "source": [
41
- "# import pandas and ipyvizzu and initialize chart\n",
42
  "\n",
43
  "import pandas as pd\n",
44
- "from ipyvizzu import Chart, Data, Config, Style\n",
 
45
  "\n",
46
  "\n",
47
- "chart = Chart(width=\"640px\", height=\"360px\")\n",
48
- "# chart = Chart(width=\"640px\", height=\"360px\", display=\"begin\")\n",
49
- "# chart = Chart(width=\"640px\", height=\"360px\", display=\"actual\") # default\n",
50
- "# chart = Chart(width=\"640px\", height=\"360px\", display=\"end\")\n",
51
- "# chart = Chart(width=\"640px\", height=\"360px\", display=\"manual\")\n"
52
- ]
53
- },
54
- {
55
- "cell_type": "code",
56
- "execution_count": null,
57
- "id": "1a26e2e9",
58
- "metadata": {},
59
- "outputs": [],
60
- "source": [
61
- "# add data\n",
 
 
 
 
 
 
 
 
62
  "\n",
63
  "data = Data()\n",
64
- "data_frame = pd.read_csv(\"https://ipyvizzu.vizzuhq.com/0.14/showcases/titanic/titanic.csv\")\n",
 
 
65
  "data.add_data_frame(data_frame)\n",
66
  "\n",
67
- "chart.animate(data)\n"
68
- ]
69
- },
70
- {
71
- "cell_type": "code",
72
- "execution_count": null,
73
- "id": "1ab7ece9",
74
- "metadata": {},
75
- "outputs": [],
76
- "source": [
77
- "# add config\n",
78
  "\n",
79
- "chart.animate(Config({\"x\": \"Count\", \"y\": \"Sex\", \"label\": \"Count\",\"title\":\"Passengers of the Titanic\"}))\n",
80
- "chart.animate(Config({\"x\": [\"Count\",\"Survived\"], \"label\": [\"Count\",\"Survived\"], \"color\": \"Survived\"}))\n",
81
- "chart.animate(Config({\"x\": \"Count\", \"y\": [\"Sex\",\"Survived\"]}))"
82
- ]
83
- },
84
- {
85
- "cell_type": "code",
86
- "execution_count": null,
87
- "id": "9ab1ecf9",
88
- "metadata": {},
89
- "outputs": [],
90
- "source": [
91
- "# add style\n",
92
  "\n",
93
- "chart.animate(Style({\"title\": {\"fontSize\": 35}}))\n"
94
- ]
95
- },
96
- {
97
- "cell_type": "code",
98
- "execution_count": null,
99
- "id": "e4ded5cf",
100
- "metadata": {},
101
- "outputs": [],
102
- "source": [
103
- "# filter data by the selected gender\n",
104
  "\n",
105
- "data_filter = Data.filter(f\"record['Sex'] == '{gender}'\")\n",
106
- "chart.animate(data_filter)\n"
107
- ]
108
- },
109
- {
110
- "cell_type": "code",
111
- "execution_count": null,
112
- "id": "e4ded5cf",
113
- "metadata": {},
114
- "outputs": [],
115
- "source": [
116
- "# display chart with show() method if display=\"manual\"\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  "\n",
118
- "# chart.show()\n"
119
  ]
120
  }
121
  ],
 
1
  {
2
  "cells": [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  {
4
  "cell_type": "code",
5
  "execution_count": null,
6
+ "id": "e4ded5cf",
7
  "metadata": {},
8
  "outputs": [],
9
  "source": [
10
+ "# import pandas and ipyvizzu\n",
11
  "\n",
12
  "import pandas as pd\n",
13
+ "from ipyvizzu import Chart, Data, Config, Style, DisplayTarget\n",
14
+ "import mercury as mr\n",
15
  "\n",
16
  "\n",
17
+ "# setup Mercury App\n",
18
+ "app = mr.App(\n",
19
+ " title=\"Data animation\", description=\"Titanic data animation\"\n",
20
+ ")\n",
21
+ "\n",
22
+ "\n",
23
+ "# add widget\n",
24
+ "gender = mr.Select(\n",
25
+ " label=\"Select sex\", value=\"female\", choices=[\"female\", \"male\"]\n",
26
+ ")\n",
27
+ "\n",
28
+ "\n",
29
+ "# initialize Chart\n",
30
+ "\n",
31
+ "chart = Chart(\n",
32
+ " width=\"640px\", height=\"360px\"\n",
33
+ ") # or Chart(width=\"640px\", height=\"360px\", display=DisplayTarget.ACTUAL)\n",
34
+ "# chart = Chart(width=\"640px\", height=\"360px\", display=DisplayTarget.BEGIN)\n",
35
+ "# chart = Chart(width=\"640px\", height=\"360px\", display=DisplayTarget.END)\n",
36
+ "# chart = Chart(width=\"640px\", height=\"360px\", display=DisplayTarget.MANUAL)\n",
37
+ "\n",
38
+ "\n",
39
+ "# add data to Chart\n",
40
  "\n",
41
  "data = Data()\n",
42
+ "data_frame = pd.read_csv(\n",
43
+ " \"https://ipyvizzu.vizzuhq.com/latest/showcases/titanic/titanic.csv\"\n",
44
+ ")\n",
45
  "data.add_data_frame(data_frame)\n",
46
  "\n",
47
+ "chart.animate(data)\n",
 
 
 
 
 
 
 
 
 
 
48
  "\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  "\n",
50
+ "# add config to Chart\n",
 
 
 
 
 
 
 
 
 
 
51
  "\n",
52
+ "chart.animate(\n",
53
+ " Config(\n",
54
+ " {\n",
55
+ " \"x\": \"Count\",\n",
56
+ " \"y\": \"Sex\",\n",
57
+ " \"label\": \"Count\",\n",
58
+ " \"title\": \"Passengers of the Titanic\",\n",
59
+ " }\n",
60
+ " )\n",
61
+ ")\n",
62
+ "chart.animate(\n",
63
+ " Config(\n",
64
+ " {\n",
65
+ " \"x\": [\"Count\", \"Survived\"],\n",
66
+ " \"label\": [\"Count\", \"Survived\"],\n",
67
+ " \"color\": \"Survived\",\n",
68
+ " }\n",
69
+ " )\n",
70
+ ")\n",
71
+ "chart.animate(Config({\"x\": \"Count\", \"y\": [\"Sex\", \"Survived\"]}))\n",
72
+ "\n",
73
+ "\n",
74
+ "# add style to Chart\n",
75
+ "\n",
76
+ "chart.animate(Style({\"title\": {\"fontSize\": 35}}))\n",
77
+ "\n",
78
+ "\n",
79
+ "# filter data by the selected gender to Chart\n",
80
+ "\n",
81
+ "data_filter = Data.filter(f\"record['Sex'] == '{gender.value}'\")\n",
82
+ "chart.animate(data_filter)\n",
83
+ "\n",
84
+ "\n",
85
+ "# display Chart with show method (display=DisplayTarget.MANUAL)\n",
86
  "\n",
87
+ "# chart.show()"
88
  ]
89
  }
90
  ],