I did a numerical calculation, which is my job. The program is an improvement of the Python one I had before, but it involves convergence calculations, and I've always wanted to create something like a simple flowchart to show the calculation procedure. So, I made a program to make "like a flowchart" in Python. I thought about it in various ways, but in the end, I couldn't come up with a good idea, and the content was just to let the computer do the same thing as handwriting by embedding Polygon and text in the code instead of handwriting with a ruler and pencil on graph paper. At first, I intended to use only flowcharts, but the same tone is cooler for related items such as variable explanations, so I also made a program to create a table. In essence, it is no different from a flowchart program. The content of the program is super primitive, but the output is black and white, but it may be quite cool (self-satisfaction). The programming environment is computer: MacBook Pro (Retina, 13-inch, Mid 2014), Python 3.5.2. Since I am working overseas, there is no particular need to output in Japanese, so please understand that the output is a poor English expression.
What are the benefits of creating something like this in Python? .. .. .. .. ..
Is it such a place? Eventually, I would like to devise a way to draw such a figure more efficiently.
A part of the program body is shown below.
A = [0, 0.7, 1.4, ... ] `` `, But it is difficult to use, so we are preparing for the procedure to change this to the display of` `` B = [0, 1, 2, ...] `` `. The actual vertical axis coordinates are displayed with
plt.yticks (A, B)` ``.python
# Flowchart
from math import *
import sys
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from matplotlib.ticker import *
param=sys.argv
iflag=int(param[1]) # flag for axis drawing
# 0: without axis and grid, 1: with axis and grid
# drawing area: w x h = 16 x 25 imaged A4 paper
xmin=-8
xmax=8
ymin=0
ymax=25
dh=0.7 # height of one row
A=[] # actural y-axis
B=[] # grid number in y-axis
for i in range(0,int(ymax//dh)+1):
s='{0:.1f}'.format(dh*i)
A=A+[float(s)]
B=B+[i]
fnameF='fig_flowchart.png'
fig = plt.figure()
ax1=plt.subplot(111)
ax1 = plt.gca()
ax1.set_xlim([xmin,xmax])
ax1.set_ylim([ymax,ymin])
aspect = (abs(ymax-ymin))/(abs(xmax-xmin))*abs(ax1.get_xlim()[1] - ax1.get_xlim()[0]) / abs(ax1.get_ylim()[1] - ax1.get_ylim()[0])
ax1.set_aspect(aspect)
if iflag==0:
plt.axis('off')
else:
ax1.tick_params(labelsize=6)
ax1.xaxis.set_major_locator(MultipleLocator(1))
ax1.yaxis.set_major_locator(MultipleLocator(dh))
plt.yticks(A,B)
plt.grid(which='both',lw=0.3, color='#cccccc',linestyle='-')
#################################################
# #
# (something to draw) #
# #
#################################################
plt.savefig(fnameF, dpi=200, bbox_inches="tight", pad_inches=0.2)
#plt.show()
Program th> | Description th> tr> |
---|---|
py_fig_flowchart.py td> | Flowchart creation program td> tr > |
py_fig_table.py td> | Table Creator td> tr > |
The left side of the result diagram is the table creation program, and the right side is the one drawn by the flowchart creation program, which is combined with ImageMagick to make one image. The execution script is as follows.
a.txt
python py_fig_flowchart.py 0
python py_fig_table.py 0
convert -trim fig_flowchart.png -bordercolor 'white' -border 10x10 fig_flowchart.png
convert -trim fig_table.png -bordercolor 'white' -border 10x10 fig_table.png
montage -tile 2x1 -geometry 465x670 fig_table.png fig_flowchart.png fig_floodroutine.png
The deliverables are as follows. There is no such thing as "Is this flow an infinite loop?"
that's all
Recommended Posts