|
618 | 618 | { |
619 | 619 | "data": { |
620 | 620 | "text/plain": [ |
621 | | - "['g', 'a', 'f', 'c', 'e', 'd', 'h', 'b']" |
| 621 | + "['g', 'e', 'b', 'd', 'a', 'f', 'h', 'c']" |
622 | 622 | ] |
623 | 623 | }, |
624 | 624 | "execution_count": null, |
|
1249 | 1249 | { |
1250 | 1250 | "data": { |
1251 | 1251 | "text/plain": [ |
1252 | | - "Path('.ipynb_checkpoints')" |
| 1252 | + "Path('hamel.py')" |
1253 | 1253 | ] |
1254 | 1254 | }, |
1255 | 1255 | "execution_count": null, |
|
1283 | 1283 | { |
1284 | 1284 | "data": { |
1285 | 1285 | "text/plain": [ |
1286 | | - "(Path('../fastcore/net.py'), Path('03a_parallel.ipynb'))" |
| 1286 | + "(Path('../fastcore/xtras.py'), Path('08_script.ipynb'))" |
1287 | 1287 | ] |
1288 | 1288 | }, |
1289 | 1289 | "execution_count": null, |
|
1400 | 1400 | "outputs": [], |
1401 | 1401 | "source": [ |
1402 | 1402 | "#export\n", |
1403 | | - "def _sparkchar(x, mn, incr, empty_zero):\n", |
| 1403 | + "def _ceil(x, lim=None): return x if (not lim or x <= lim) else lim\n", |
| 1404 | + "\n", |
| 1405 | + "def _sparkchar(x, mn, mx, incr, empty_zero):\n", |
1404 | 1406 | " if x is None or (empty_zero and not x): return ' '\n", |
1405 | 1407 | " if incr == 0: return spark_chars[0]\n", |
1406 | | - " res = int((x-mn)/incr-0.5)\n", |
| 1408 | + " res = int((_ceil(x,mx)-mn)/incr-0.5)\n", |
1407 | 1409 | " return spark_chars[res]" |
1408 | 1410 | ] |
1409 | 1411 | }, |
|
1419 | 1421 | " valid = [o for o in data if o is not None]\n", |
1420 | 1422 | " if not valid: return ' '\n", |
1421 | 1423 | " mn,mx,n = ifnone(mn,min(valid)),ifnone(mx,max(valid)),len(spark_chars)\n", |
1422 | | - " res = [_sparkchar(o,mn,(mx-mn)/n,empty_zero) for o in data]\n", |
| 1424 | + " res = [_sparkchar(x=o, mn=mn, mx=mx, incr=(mx-mn)/n, empty_zero=empty_zero) for o in data]\n", |
1423 | 1425 | " return ''.join(res)" |
1424 | 1426 | ] |
1425 | 1427 | }, |
|
1443 | 1445 | "print(f' with \"empty_zero\": {sparkline(data, empty_zero=True )}')" |
1444 | 1446 | ] |
1445 | 1447 | }, |
| 1448 | + { |
| 1449 | + "cell_type": "markdown", |
| 1450 | + "metadata": {}, |
| 1451 | + "source": [ |
| 1452 | + "You can set a maximum and minimum for the y-axis of the sparkline with the arguments `mn` and `mx` respectively:" |
| 1453 | + ] |
| 1454 | + }, |
| 1455 | + { |
| 1456 | + "cell_type": "code", |
| 1457 | + "execution_count": null, |
| 1458 | + "metadata": {}, |
| 1459 | + "outputs": [ |
| 1460 | + { |
| 1461 | + "data": { |
| 1462 | + "text/plain": [ |
| 1463 | + "'▂▅▇▇'" |
| 1464 | + ] |
| 1465 | + }, |
| 1466 | + "execution_count": null, |
| 1467 | + "metadata": {}, |
| 1468 | + "output_type": "execute_result" |
| 1469 | + } |
| 1470 | + ], |
| 1471 | + "source": [ |
| 1472 | + "sparkline([1,2,3,400], mn=0, mx=3)" |
| 1473 | + ] |
| 1474 | + }, |
1446 | 1475 | { |
1447 | 1476 | "cell_type": "code", |
1448 | 1477 | "execution_count": null, |
|
1531 | 1560 | "name": "stdout", |
1532 | 1561 | "output_type": "stream", |
1533 | 1562 | "text": [ |
1534 | | - "Num Events: 3, Freq/sec: 272.3\n", |
1535 | | - "Most recent: ▇▁▁▂▁ 460.5 360.2 359.1 391.6 379.3\n" |
| 1563 | + "Num Events: 7, Freq/sec: 346.2\n", |
| 1564 | + "Most recent: ▃▇▆▁▆ 320.1 427.2 389.6 208.7 401.4\n" |
1536 | 1565 | ] |
1537 | 1566 | } |
1538 | 1567 | ], |
|
0 commit comments