diff --git a/lisp/my/img/figure-matplotlib-tex.svg b/lisp/my/img/figure-matplotlib-tex.svg new file mode 100644 index 00000000..a04f6e9f --- /dev/null +++ b/lisp/my/img/figure-matplotlib-tex.svg @@ -0,0 +1,1580 @@ + + + + + + + + 2022-12-04T21:31:02.664055 + image/svg+xml + + + Matplotlib v3.6.2, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lisp/my/img/figure-matplotlib.svg b/lisp/my/img/figure-matplotlib.svg new file mode 100644 index 00000000..82c85a64 --- /dev/null +++ b/lisp/my/img/figure-matplotlib.svg @@ -0,0 +1,1722 @@ + + + + + + + + 2022-12-04T21:20:23.407285 + image/svg+xml + + + Matplotlib v3.6.2, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lisp/my/my-org-article.org b/lisp/my/my-org-article.org index c655257f..c0a85ec2 100644 --- a/lisp/my/my-org-article.org +++ b/lisp/my/my-org-article.org @@ -359,7 +359,7 @@ print(result) |---------+-------| ** Figures -*** svg +*** Include svg #+NAME: fig-svg #+CAPTION: svg figure #+ATTR_ORG: :width 100 @@ -367,7 +367,7 @@ print(result) [[/usr/share/icons/hicolor/scalable/apps/emacs.svg]] See figure ref:fig-svg-import as a reference. -*** png +*** Include png #+NAME: fig-png #+CAPTION: png figure #+ATTR_ORG: :width 100 @@ -414,6 +414,78 @@ See figure ref:fig-svg-import as a reference. [[file:test-tikz.svg]] #+end_figure +*** python using matplotlib + +SRC block header =:prologue (mpl-prologue)= for non-latex exports (.svg +exports) to loads my.mplstyle including kpfonts. Other style via +optional argument, e.g. =:prologue (mpl-prologue "my-tex")= rendering +via latex including kpfonts. + +SRC block header =:var fname=(mpl-var "")= to export figure +as .pgf for latex and .svg otherwise, like HTML. + +**** using my.mplstyle +#+HEADER: :prologue (mpl-prologue) +#+HEADER: :var fname=(mpl-var "img/figure-matplotlib") +#+begin_src python :results output file +import math as m +import matplotlib as mpl + +n = 30 +t = [i/n*m.pi for i in range(n+1)] + +fig, ax = plt.subplots() +[ax.plot(t, [m.sin(i+j/12*m.pi) for i in t], color=f'C{j}', label=f'$C_{j}$') for j in range(10)] +ax.legend() +ax.set_title(r'Functions: $\sin(x + \pi \, i/12)$') +ax.set_xlabel(r'$x ~ \times \pi$') +ax.set_ylabel('$y$') +ax.set_xticks([0, m.pi/4, m.pi/2, m.pi*3/4, m.pi]) +ax.set_xticklabels([0.00, 0.25, 0.50, 0.75, 1.00]) +ax.xaxis.set_minor_locator(mpl.ticker.AutoMinorLocator(3)) +ax.grid() +ax.grid(which='minor', linestyle=':') + +fig.savefig(fname) +plt.close() +print(fname, end='') +#+end_src + +#+ATTR_ORG: :width 500 +#+RESULTS: +[[file:img/figure-matplotlib.svg]] + +**** using my-tex.mplstyle +#+HEADER: :prologue (mpl-prologue "my-tex") +#+HEADER: :var fname=(mpl-var "img-matplotlib-tex") +#+begin_src python :results output file +import math as m +import matplotlib as mpl + +n = 30 +t = [i/n*m.pi for i in range(n+1)] + +fig, ax = plt.subplots() +[ax.plot(t, [m.sin(i+j/12*m.pi) for i in t], color=f'C{j}', label=f'$C_{j}$') for j in range(10)] +ax.legend() +ax.set_title(r'Functions: $\sin(x + \pi \, i/12)$') +ax.set_xlabel(r'$x ~ \times \pi$') +ax.set_ylabel('$y$') +ax.set_xticks([0, m.pi/4, m.pi/2, m.pi*3/4, m.pi]) +ax.set_xticklabels([0.00, 0.25, 0.50, 0.75, 1.00]) +ax.xaxis.set_minor_locator(mpl.ticker.AutoMinorLocator(3)) +ax.grid() +ax.grid(which='minor', linestyle=':') + +fig.savefig(fname) +plt.close() +print(fname, end='') +#+end_src + +#+ATTR_ORG: :width 500 +#+RESULTS: +[[file:img-matplotlib-tex.svg]] + ** Example / Verbatim #+BEGIN_EXAMPLE verbatime example