#!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt from re import findall # The following numbers were copied from http://www.cbi.ir/page/10809.aspx # which is a PDF file from the official website of Central Bank of Iran. # Available to download from: http://www.cbi.ir/simplelist/10807.aspx text = """24/4 1/480 1371 4/5 0/052 1343 22/9 1/814 1372 0/3 0/052 1344 21/2 0/004 1316 35/2 2/456 1373 0/8 0/052 1345 8/8 0/004 1317 49/4 3/665 1374 0/8 0/052 1346 8/0 0/004 1318 23/2 4/520 1375 1/5 0/052 1347 13/8 0/004 1319 17/3 5/298 1376 3/6 0/052 1348 49/5 0/008 1320 18/1 6/258 1377 1/5 0/056 1349 96/2 0/012 1321 20/1 7/516 1378 5/5 0/056 1350 110/5 0/028 1322 12/6 8/463 1379 6/3 0/060 1351 2/7 0/028 1323 11/4 9/427 1380 11/2 0/069 1352 -14/4 0/024 1324 15/8 10/915 1381 15/5 0/077 1353 -11/5 0/020 1325 15/6 12/624 1382 9/9 0/085 1354 6/6 0/024 1326 15/2 14/544 1383 16/6 0/101 1355 11/1 0/024 1327 10/4 16/048 1384 25/1 0/125 1356 2/3 0/028 1328 1 / 11/9 17/955 1385 10/0 0/137 1357 -17/2 0/020 1329 18/4 21/265 1386 11/4 0/153 1358 8/3 0/024 1330 25/4 26/660 1387 23/5 0/190 1359 7/2 0/024 1331 10/8 29/527 1388 22/8 0/234 1360 9/2 0/028 1332 12/4 33/188 1389 19/2 0/278 1361 15/9 0/032 1333 21/5 40/321 1390 14/8 0/319 1362 1/7 0/032 1334 30/5 52/635 1391 10/4 0/355 1363 8/8 0/036 1335 34/7 70/916 1392 6/9 0/379 1364 4/4 0/036 1336 15/6 81/948 1393 23/7 0/468 1365 1/0 0/036 1337 11/9 91/714 1394 27/7 0/597 1366 13/0 0/044 1338 9/0 100/000 1395 28/9 0/770 1367 7/9 0/048 1339 9/6 109/650 1396 17/4 0/903 1368 1/6 0/048 1340 9/0 0/984 1369 0/9 0/048 1341 20/7 1/189 1370 1/0 0/048 1342 """ text = text.replace('/', '.') data = findall(r'([\d.]+)\s+[\d.]+\s+(\d\d\d\d)', text) years_inflations = sorted( (int(d[1]), float(d[0])) for d in data if d[1] >= '1325') xs = np.array([yi[0] for yi in years_inflations]) ys = np.array([yi[1] for yi in years_inflations]) fig = plt.figure() ax = fig.add_subplot(111) axistexts = ax.set_xticklabels([str(x) for x in xs]) plt.setp(axistexts, rotation=-45, fontsize=10, clip_on=False) plt.xlim(xs[0] - 1, xs[-1] + 1) plt.xticks(xs[::5], xs[::5]) plt.ylim(0) plt.yticks(range(0, 52, 5)) plt.ylabel('% Annual inflation rate') plt.plot(xs, ys, "#b32424", marker='.', lw=1) ax.fill_between(xs, ys, interpolate=True, color='#fef6e7') plt.grid(which='both') plt.savefig(f'Inflation_rate_in_Iran_({xs[0]}-{xs[-1]}).svg') plt.show()