Commit b2ebd954 authored by Katharina Przybill's avatar Katharina Przybill
Browse files

Update equidistancePlot.py

parent f52410a8
......@@ -9,70 +9,87 @@ import psycopg2
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
import sys
def equidistance(inTextFile,outJpegFile):
equ_first_list = []
equ_last_list = []
equ_dev_list = []
with open(inTextFile) as f:
for line in f.readlines():
line = line.split(";")
if len(line) > 0:
equ_first = line[0].replace(",",".")
equ_first = float(equ_first)
equ_first_list.append(equ_first)
equ_last = line[1].replace(",",".")
equ_last = float(equ_last)
equ_last_list.append(equ_last)
equ_dev_list.append(equ_first-equ_last)
# improvement of equidistance average
equ_av = sum(equ_dev_list)/len(equ_dev_list)
# not changed polygons
poly_unchanged = (100.0/len(equ_dev_list))* (equ_dev_list.count(0.0))
# improvement of geometric representation of polygons
count_improved = 0
for i, equ_first in enumerate(equ_first_list):
if equ_last_list[i] < equ_first:
count_improved += 1
improved_geom = (100.0/len(equ_first_list)) * count_improved
print str(count_improved) + " " + str(len(equ_first_list))
equ_first_list = []
equ_dev_list = []
with open("D:\\katha\\filter\\equidistance\\unclipped\\equ_stg.txt") as f:
for line in f.readlines():
line = line.split(";")
if len(line) > 0:
equ_first = line[0].replace(",",".")
equ_first = float(equ_first)
equ_first_list.append(equ_first)
equ_dev = line[1].replace(",",".")
equ_dev = float(equ_dev)
equ_dev_list.append(equ_dev)
col1 = equ_first_list #
devel_equ = equ_dev_list #
print "improvement of equidistance average " + str(equ_av) +" m"
print "per cent of unchanged polygons " + str(poly_unchanged) + " %"
print "per cent of polygons with improvemnt of geometric representation " + str(improved_geom) + " %"
###
### Plot (Line-Chart)
###
# improvement of equidistance average
equ_av = sum(equ_dev_list)/len(equ_dev_list)
# not changed polygons
poly_unchanged = (100.0/len(equ_dev_list))* (equ_dev_list.count(0.0))
# improvement of geometric representation of polygons
fig, ax = plt.subplots()
print equ_av
print poly_unchanged
###
### Plot (Line-Chart)
###
# Create linechart
plt.plot(equ_dev_list, color = '#ff6700', linewidth=2, label='Development of the Equidistance')
# Place a gray dashed grid behind the thicks (only for y-axis)
ax.xaxis.grid(color='gray', linestyle='dashed')
ax.yaxis.grid(color='gray', linestyle='dashed')
fig, ax = plt.subplots()
# Set this grid behind the thicks
ax.set_axisbelow(True)
# Create linechart
plt.plot(devel_equ, color = '#ff6700', linewidth=2, label='Development of the Equidistance')
# Rotate x-labels on the x-axis
fig.autofmt_xdate()
# Place a gray dashed grid behind the thicks (only for y-axis)
ax.xaxis.grid(color='gray', linestyle='dashed')
ax.yaxis.grid(color='gray', linestyle='dashed')
# Label x and y axis
x_str = ('Polygons with a "natural" or "landuse"-Tag')
# Set this grid behind the thicks
ax.set_axisbelow(True)
plt.xlabel(x_str)
# Rotate x-labels on the x-axis
fig.autofmt_xdate()
plt.ylabel('Change of Equidistance [m]')
# Label x and y axis
x_str = ('Polygons with a "natural" or "landuse"-Tag')
# place legend
ax.legend(loc='upper center', prop={'size':12})
plt.xlabel(x_str)
# Plot-title
plt.title('Equidistance Development of Polygons with "natural" or "landuse"-Tag"')
plt.ylabel('Change of Equidistance [m]')
# Save plot to *.jpeg-file
# place legend
ax.legend(loc='upper center', prop={'size':12})
plt.savefig(outJpegFile)
# Plot-title
plt.title('Equidistance Development of Polygons with "natural" or "landuse"-Tag"')
plt.clf()
return
# Save plot to *.jpeg-file
plt.savefig('D:\\katha\\filter\\diagramme\\equidist_stg.jpeg')
plt.clf()
\ No newline at end of file
if __name__ == '__main__':
if len(sys.argv) == 3:
inTextFile = sys.argv[1]
outJpegFile = sys.argv[2]
equidistance(inTextFile,outJpegFile)
else:
print "usage: 3 commandline arguments are needed: the script itself, the .txt file \nwith the equidistance results and a .jpeg filepath to save the plot.\n<script.py inTextfile.txt outJpegFile.jpeg>"
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment