{"id":3953,"date":"2021-11-05T09:45:06","date_gmt":"2021-11-05T14:45:06","guid":{"rendered":"http:\/\/blog.espol.edu.ec\/girni\/?p=3953"},"modified":"2022-07-25T06:43:14","modified_gmt":"2022-07-25T11:43:14","slug":"ubica-los-puntos-en-grafica-2d-o-3d","status":"publish","type":"post","link":"https:\/\/blog.espol.edu.ec\/girni\/ubica-los-puntos-en-grafica-2d-o-3d\/","title":{"rendered":"3.2 Ubica los puntos en gr\u00e1fica 2D o 3D"},"content":{"rendered":"<p>Se grafica la ubicaci\u00f3n de los puntos usando las coordenadas este, norte y altura registradas con el GPS. Las gr\u00e1ficas se pueden realizar en 2D y en 3D, lo que ofrece una vista de la ubicaci\u00f3n general de los puntos respecto a los gateways.<\/p>\n<p><a href=\"http:\/\/blog.espol.edu.ec\/girni\/files\/2022\/02\/LoRaWan_Granja_rotando3D01.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3954 aligncenter\" src=\"http:\/\/blog.espol.edu.ec\/girni\/files\/2022\/02\/LoRaWan_Granja_rotando3D01.gif\" alt=\"\" width=\"512\" height=\"384\" \/><\/a>La vista en 2d es semejante a la que se encuentra en GoogleEarth<\/p>\n<p><a href=\"http:\/\/blog.espol.edu.ec\/girni\/files\/2022\/02\/LoRaWan_Granja01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3956\" src=\"http:\/\/blog.espol.edu.ec\/girni\/files\/2022\/02\/LoRaWan_Granja01.png\" alt=\"\" width=\"1303\" height=\"711\" srcset=\"https:\/\/blog.espol.edu.ec\/girni\/files\/2022\/02\/LoRaWan_Granja01.png 1303w, https:\/\/blog.espol.edu.ec\/girni\/files\/2022\/02\/LoRaWan_Granja01-300x164.png 300w, https:\/\/blog.espol.edu.ec\/girni\/files\/2022\/02\/LoRaWan_Granja01-768x419.png 768w, https:\/\/blog.espol.edu.ec\/girni\/files\/2022\/02\/LoRaWan_Granja01-1024x559.png 1024w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<h2>Instrucciones en Python<\/h2>\n<pre><span style=\"color: #ff0000\"># Datos desde GPS archivo.csv<\/span>\r\n<span style=\"color: #ff0000\"># Graficas de coordenadas 2D o 3D<\/span>\r\n<span style=\"color: #ff0000\"># Girni 2020-10-07 edelros@espol.edu.ec<\/span>\r\n<span style=\"color: #d35400\">import<\/span> numpy <span style=\"color: #d35400\">as<\/span> np\r\n<span style=\"color: #d35400\">import<\/span> pandas <span style=\"color: #d35400\">as<\/span> pd\r\n<span style=\"color: #d35400\">import<\/span> matplotlib.pyplot <span style=\"color: #d35400\">as<\/span> plt\r\n<span style=\"color: #d35400\">from<\/span> mpl_toolkits.mplot3d <span style=\"color: #d35400\">import<\/span> Axes3D\r\n<span style=\"color: #d35400\">import<\/span> matplotlib.animation <span style=\"color: #d35400\">as<\/span> animation\r\n\r\n<span style=\"color: #ff0000\"># INGRESO<\/span>\r\n<span style=\"color: #ff0000\"># Archivo procesado con distancias<\/span>\r\narch_gpsrsm = <span style=\"color: #008000\">'Coordenadas\/coord_puntos.csv'<\/span>\r\narch_rotacion = <span style=\"color: #008000\">'Coordenadas\/rotando3D.gif'<\/span>\r\n\r\n<span style=\"color: #ff0000\"># Parametros de gr\u00e1fica<\/span>\r\nalturaantena = 8\r\ntipograf = <span style=\"color: #008000\">'3D'<\/span> <span style=\"color: #ff0000\"># '2D','3D'<\/span>\r\netiquetar = [<span style=\"color: #008000\">'Gw03'<\/span>,<span style=\"color: #008000\">'LOS08'<\/span>,<span style=\"color: #008000\">'CD01'<\/span>,<span style=\"color: #008000\">'CD11'<\/span>,<span style=\"color: #008000\">'CAG1'<\/span>,<span style=\"color: #008000\">'MA10'<\/span>]\r\ngrupo   = [<span style=\"color: #008000\">'LOS'<\/span>,<span style=\"color: #008000\">'Ref'<\/span>,<span style=\"color: #008000\">'M'<\/span>,<span style=\"color: #008000\">'C'<\/span>, ]\r\ncolores = [<span style=\"color: #008000\">'grey'<\/span>,<span style=\"color: #008000\">'magenta'<\/span>,<span style=\"color: #008000\">'green'<\/span>,<span style=\"color: #008000\">'brown'<\/span>,]\r\n\r\n<span style=\"color: #ff0000\"># PROCEDIMIENTO<\/span>\r\n<span style=\"color: #ff0000\"># leer coordenadas<\/span>\r\nubica = pd.read_csv(arch_gpsrsm, index_col=<span style=\"color: #008000\">'punto'<\/span>)\r\nubica = pd.DataFrame(ubica)\r\nn = <span style=\"color: #ff00ff\">len<\/span>(ubica)\r\n\r\n<span style=\"color: #ff0000\"># colores y alturas<\/span>\r\nubica[<span style=\"color: #008000\">'color'<\/span>] = <span style=\"color: #008000\">'Red'<\/span>\r\n<span style=\"color: #d35400\">for<\/span> unpunto <span style=\"color: #d35400\">in<\/span> ubica.index:\r\n    <span style=\"color: #ff0000\"># revisa grupo<\/span>\r\n    <span style=\"color: #d35400\">for<\/span> i <span style=\"color: #d35400\">in<\/span> <span style=\"color: #ff00ff\">range<\/span>(0,<span style=\"color: #ff00ff\">len<\/span>(grupo),1):\r\n        <span style=\"color: #d35400\">if<\/span> unpunto.startswith(grupo[i]):\r\n            ubica.at[unpunto,<span style=\"color: #008000\">'color'<\/span>] = colores[i]\r\n    <span style=\"color: #d35400\">if<\/span> unpunto.startswith(<span style=\"color: #008000\">'Gw'<\/span>):\r\n        ubica.at[unpunto,<span style=\"color: #008000\">'altitud'<\/span>] = ubica.at[unpunto,<span style=\"color: #008000\">'altitud'<\/span>]+alturaantena\r\n<span style=\"color: #ff00ff\">print<\/span> (ubica[<span style=\"color: #008000\">'color'<\/span>])\r\n    \r\n<span style=\"color: #ff0000\"># SALIDA<\/span>\r\n<span style=\"color: #ff00ff\">print<\/span>(ubica.head())\r\n\r\n<span style=\"color: #ff0000\"># Grafica 2D --------------------------<\/span>\r\n<span style=\"color: #d35400\">if<\/span> tipograf == <span style=\"color: #008000\">'2D'<\/span>:\r\n    figura, grafica = plt.subplots()\r\n    <span style=\"color: #d35400\">for<\/span> unpunto <span style=\"color: #d35400\">in<\/span> ubica.index:\r\n        unalon = ubica[<span style=\"color: #008000\">'utm_este'<\/span>][unpunto]\r\n        unalat = ubica[<span style=\"color: #008000\">'utm_norte'<\/span>][unpunto]\r\n        unaalt = ubica[<span style=\"color: #008000\">'altitud'<\/span>][unpunto]\r\n        uncolor = ubica[<span style=\"color: #008000\">'color'<\/span>][unpunto] \r\n        condicion = <span style=\"color: #d35400\">not<\/span>(unpunto.startswith(<span style=\"color: #008000\">'Ref'<\/span>))\r\n        <span style=\"color: #d35400\">if<\/span> condicion:\r\n            grafica.scatter(unalon,unalat,\r\n                            color = uncolor,\r\n                            label = unpunto)\r\n            <span style=\"color: #d35400\">if<\/span> unpunto <span style=\"color: #d35400\">in<\/span> etiquetar:\r\n                grafica.annotate(unpunto,(unalon,unalat),\r\n                                 color = uncolor,\r\n                                 rotation=45)\r\n    plt.xlabel(<span style=\"color: #008000\">'UTM_este'<\/span>)\r\n    plt.ylabel(<span style=\"color: #008000\">'UTM_norte'<\/span>)\r\n    plt.title(<span style=\"color: #008000\">'Ubicacion UTM'<\/span>)\r\n    plt.grid()\r\n    plt.show()\r\n\r\n<span style=\"color: #ff0000\"># Grafica 3D --------------------------<\/span>\r\n<span style=\"color: #d35400\">if<\/span> tipograf == <span style=\"color: #008000\">'3D'<\/span>:\r\n    figura = plt.figure()\r\n    grafica = figura.add_subplot(projection=<span style=\"color: #008000\">'3d'<\/span>)\r\n    <span style=\"color: #ff0000\"># grafica = plt.figure().add_subplot(projection='3d')<\/span>\r\n    <span style=\"color: #d35400\">for<\/span> unpunto <span style=\"color: #d35400\">in<\/span> ubica.index:\r\n        unalon  = ubica[<span style=\"color: #008000\">'utm_este'<\/span>][unpunto]\r\n        unalat  = ubica[<span style=\"color: #008000\">'utm_norte'<\/span>][unpunto]\r\n        unaalt  = ubica[<span style=\"color: #008000\">'altitud'<\/span>][unpunto]\r\n        uncolor = ubica[<span style=\"color: #008000\">'color'<\/span>][unpunto] \r\n        condicion = <span style=\"color: #d35400\">not<\/span>(unpunto.startswith(<span style=\"color: #008000\">'Ref'<\/span>))\r\n        <span style=\"color: #d35400\">if<\/span> condicion:\r\n            grafica.scatter(unalon,unalat,unaalt,\r\n                            color = uncolor,\r\n                            label = unpunto)\r\n        <span style=\"color: #d35400\">if<\/span> unpunto <span style=\"color: #d35400\">in<\/span> etiquetar:\r\n            grafica.text(unalon,unalat,unaalt,unpunto)\r\n    grafica.set_xlabel(<span style=\"color: #008000\">'UTM_este'<\/span>)\r\n    grafica.set_ylabel(<span style=\"color: #008000\">'UTM_norte'<\/span>)\r\n    grafica.set_zlabel(<span style=\"color: #008000\">'altitud'<\/span>)\r\n    grafica.set_title(<span style=\"color: #008000\">'Ubicacion UTM'<\/span>)\r\n\r\n    <span style=\"color: #d35400\">def<\/span> <span style=\"color: #0000e6\">rotate<\/span>(angle):\r\n        grafica.view_init(azim=angle)\r\n\r\n    <span style=\"color: #ff00ff\">print<\/span>(<span style=\"color: #008000\">\"realizando animation\"<\/span>)\r\n    rot_animation = animation.FuncAnimation(figura,\r\n                    rotate,\r\n                    frames = np.arange(45,360+45,10),\r\n                    interval = 200)\r\n    rot_animation.save(arch_rotacion, dpi=80,\r\n                    writer = animation.PillowWriter(fps=5))\r\n    plt.show()\r\n<\/pre>\n<p><strong>Referencia<\/strong>: <a href=\"http:\/\/blog.espol.edu.ec\/analisisnumerico\/recursos\/resumen-python\/graficas-3d-puntos-dispersos-scatter\/\">Graficas 3D puntos dispersos-scatter<\/a> en m\u00e9todos num\u00e9ricos<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Se grafica la ubicaci\u00f3n de los puntos usando las coordenadas este, norte y altura registradas con el GPS. Las gr\u00e1ficas se pueden realizar en 2D y en 3D, lo que ofrece una vista de la ubicaci\u00f3n general de los puntos respecto a los gateways. La vista en 2d es semejante a la que se encuentra &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.espol.edu.ec\/girni\/ubica-los-puntos-en-grafica-2d-o-3d\/\" class=\"more-link\">Continuar leyendo<span class=\"screen-reader-text\"> \"3.2 Ubica los puntos en gr\u00e1fica 2D o 3D\"<\/span><\/a><\/p>\n","protected":false},"author":8043,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1466681],"tags":[],"class_list":["post-3953","post","type-post","status-publish","format-standard","hentry","category-lorawan-registro-de-estados"],"_links":{"self":[{"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/posts\/3953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/users\/8043"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/comments?post=3953"}],"version-history":[{"count":4,"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/posts\/3953\/revisions"}],"predecessor-version":[{"id":3975,"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/posts\/3953\/revisions\/3975"}],"wp:attachment":[{"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/media?parent=3953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/categories?post=3953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.espol.edu.ec\/girni\/wp-json\/wp\/v2\/tags?post=3953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}