mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
tikz/pi: Add
This commit is contained in:
parent
7f1684d2c1
commit
2a30558690
5 changed files with 108 additions and 0 deletions
36
tikz/pi/create.py
Normal file
36
tikz/pi/create.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""Create a data.csv file."""
|
||||
|
||||
import csv
|
||||
|
||||
try:
|
||||
# import version included with old SymPy
|
||||
from sympy.mpmath import mp
|
||||
except ImportError:
|
||||
# import newer version
|
||||
from mpmath import mp
|
||||
|
||||
mp.dps = 1000 # set number of digits
|
||||
pi = mp.pi
|
||||
print(pi)
|
||||
|
||||
# Split pi in groups of two digits
|
||||
pi = str(pi)[2:]
|
||||
split_pi = []
|
||||
for i in range(0, len(pi), 2):
|
||||
part = pi[i:i + 2]
|
||||
if len(part) != 2:
|
||||
continue
|
||||
split_pi.append(part)
|
||||
|
||||
# Representation of pi
|
||||
data = [("x", "y", "color")] # header
|
||||
for e1, e2 in zip(split_pi, split_pi[1:]):
|
||||
tuple_date = (int(e1), int(e2), "c{}".format(int(int(e1) / 10)))
|
||||
data.append(tuple_date)
|
||||
|
||||
# Write data to csv
|
||||
with open('data.csv', 'w') as fp:
|
||||
writer = csv.writer(fp, delimiter=',')
|
||||
writer.writerows(data)
|
Loading…
Add table
Add a link
Reference in a new issue