{"id":519,"date":"2012-04-25T14:20:43","date_gmt":"2012-04-25T14:20:43","guid":{"rendered":"http:\/\/azfreeos.wordpress.com\/?p=19"},"modified":"2013-09-27T14:37:58","modified_gmt":"2013-09-27T14:37:58","slug":"draw-2-d-contour-figure-using-python","status":"publish","type":"post","link":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/2012\/04\/25\/draw-2-d-contour-figure-using-python\/","title":{"rendered":"Draw 2-D contour figure using Python"},"content":{"rendered":"<div dir=\"ltr\">\n<div>\n<div dir=\"ltr\">\n<div lang=\"en\">\n<p>File should be in ASCII format read in 2 dimensions (an example file can be downloaded).\u00a0File to read it is called &#8220;baca_2d .py&#8221;. The Python Script file is presented as follows,<\/p>\n<hr \/>\n<\/div>\n<div><\/div>\n<div>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 baca_2d.py \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n<\/div>\n<div>\n<div>\n<div>\n<div>\n<div>\n<p>import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>from numpy import *<\/p>\n<p>b = []<\/p>\n<p>data = open(&#8220;scen-7.pma&#8221;,&#8221;r&#8221;)<\/p>\n<p>barp = data.readline()<\/p>\n<p>bar \u00a0= barp.split()<\/p>\n<p>n \u00a0 \u00a0= bar[0]<\/p>\n<p>m \u00a0 \u00a0= bar[1]<\/p>\n<p>baris = data.readlines()<\/p>\n<p>for i in range(int(m)):<\/p>\n<p>kolom = baris[i].split()<\/p>\n<p>a = list(kolom)<\/p>\n<p>b = b + a<\/p>\n<p>c = list(b)<\/p>\n<p>d = reshape(array(c),(float(m),float(n)))<\/p>\n<p>cs = plt.contour(d,100)<\/p>\n<p>plt.clabel(cs, fontsize=9, inline=1)<\/p>\n<p>cs = plt.show()<\/p>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014- baca_2d.py \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n<div dir=\"ltr\">\n<div lang=\"en\">\n<p>When the file is over run with the command,<\/p>\n<\/div>\n<div lang=\"en\">\n<p>abuadnan@abuadnan-laptop:~\/Documents$ <strong>.\/baca_2d.py<\/strong><\/p>\n<\/div>\n<div lang=\"en\">\n<p>Then will come by the view as follows,<\/p>\n<\/div>\n<div lang=\"en\"><\/div>\n<p><a href=\"https:\/\/dosen.unila.ac.id\/wp-content\/uploads\/sites\/21\/2012\/04\/plot2d_python.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter\" alt=\"\" src=\"https:\/\/dosen.unila.ac.id\/wp-content\/uploads\/sites\/21\/2012\/04\/plot2d_python.jpg?w=300\" width=\"320\" height=\"179\" border=\"0\" \/><\/a><\/p>\n<div dir=\"ltr\">\n<div>\n<div dir=\"ltr\">\n<div>\n<div>\n<p style=\"text-align: center\">Figure 1. Plotting contur if python script in running.<\/p>\n<\/div>\n<\/div>\n<div><\/div>\n<div>\n<p>From Figure 1, to take the contur generated, icon &#8220;save&#8221; can be click\u00a0 so that title would look as follows,<\/p>\n<\/div>\n<div><a href=\"https:\/\/dosen.unila.ac.id\/wp-content\/uploads\/sites\/21\/2012\/04\/plot2d_py_save.jpg\"><img decoding=\"async\" class=\"aligncenter\" alt=\"\" src=\"https:\/\/dosen.unila.ac.id\/wp-content\/uploads\/sites\/21\/2012\/04\/plot2d_py_save.jpg?w=300\" width=\"320\" height=\"179\" border=\"0\" \/><\/a><\/div>\n<p style=\"text-align: center\">Figure 2. Save the picture in the format of the image (e.g., *. png).<\/p>\n<div dir=\"ltr\">\n<div><\/div>\n<div>\n<div dir=\"ltr\">\n<div>\n<p>Enter the name of the file and the desired image format (in this example is used *. png) then press &#8220;save&#8221;. The image file will be generated, such as the following example,<\/p>\n<\/div>\n<p style=\"text-align: center\"><a href=\"http:\/\/azfreeos.files.wordpress.com\/2012\/04\/plot2d_py_contour.jpg\"><img decoding=\"async\" class=\"aligncenter\" alt=\"\" src=\"http:\/\/azfreeos.files.wordpress.com\/2012\/04\/plot2d_py_contour.jpg?w=300\" width=\"320\" height=\"289\" border=\"0\" \/><\/a>Figure 3. An example contour image is generated by the python script.<\/p>\n<div dir=\"ltr\">\n<div>\n<div dir=\"ltr\">\n<div>\n<p>Figure 3 is a picture generated from a python script file with the name &#8220;baca_2d. py&#8221; run like the procedure above. Where this script reads the data file in ASCII format with the name &#8220;scen-7.pma&#8221;.\u00a0The File is read and resulting the Figure 1. From the Figure 1 the image file can be saved with the name, and the\u00a0contour\u00a0format as desired.<\/p>\n<\/div>\n<div>\n<p>So, hopefully this is helpful to all users of linux or windows that use Python as a free program (free softwares). This example File can be downloaded from <a href=\"https:\/\/dosen.unila.ac.id\/wp-content\/uploads\/sites\/21\/2013\/09\/baca2d_python.zip\" target=\"_blank\">here<\/a> (101,2 Kb).<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>File should be in ASCII format read in 2 dimensions (an example file can be downloaded).\u00a0File to read it is called &#8220;baca_2d .py&#8221;. The Python Script file is presented as &hellip; <a class=\"readmore\" href=\"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/2012\/04\/25\/draw-2-d-contour-figure-using-python\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-519","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/wp-json\/wp\/v2\/posts\/519"}],"collection":[{"href":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/wp-json\/wp\/v2\/comments?post=519"}],"version-history":[{"count":0,"href":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/wp-json\/wp\/v2\/posts\/519\/revisions"}],"wp:attachment":[{"href":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/wp-json\/wp\/v2\/media?parent=519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/wp-json\/wp\/v2\/categories?post=519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dosen.unila.ac.id\/ahmadzakaria\/wp-json\/wp\/v2\/tags?post=519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}