Skip to content

Commit

Permalink
adding pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnutriyuono committed Oct 23, 2019
1 parent 52d5dc0 commit b097806
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions TUBES-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"metadata": {},
"source": [
"# TUGAS BESAR 1 \n",
"### Mem"
"### Membuat gambar dengan algortima"
]
},
{
Expand All @@ -17,6 +17,13 @@
"from matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Fungsi round untuk membulatkan angka "
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand All @@ -27,6 +34,13 @@
" return int(a + 0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Algoritma DDA (Garis) "
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand All @@ -52,19 +66,60 @@
" return x,y"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'pd' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-25-940f53aca930>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mround_y\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mround\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'x'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'y'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[0mrd\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'round(x)'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mround_x\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'round(y)'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[0mround_y\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'round(x),round(y)'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m \u001b[1;34m\"{\"\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mrd\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"round(x)\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;34m\",\"\u001b[0m\u001b[1;33m+\u001b[0m \u001b[0mrd\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"round(y)\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m\"}\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'pd' is not defined"
]
}
],
"source": [
"x, y = dda(20,10,30,10)\n",
"round_x = [round(x) for x in x]\n",
"round_y = [round(x) for x in y]\n",
"\n",
"df = pd.DataFrame({'x': x, 'y':y})\n",
"rd = pd.DataFrame({'round(x)':round_x, 'round(y)':round_y})\n",
"df['round(x),round(y)']= \"{\"+rd[\"round(x)\"].astype(str) +\",\"+ rd[\"round(y)\"].astype(str)+\"}\"\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Cerobong Asap "
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"\n",
"xa, ya = dda(20,10,30,10)\n",
"xb, yb = dda(30,10,30,40)\n",
"xc, yc = dda(20,10,30,40)\n",
"xd, yd = dda(20,40,30,40)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plotting Garis "
]
},
{
"cell_type": "code",
"execution_count": 23,
Expand Down

0 comments on commit b097806

Please sign in to comment.