PGF preamble is not used
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Bereich
- data-visualization
Rechercherichtung
Beginnen Sie mit der Julia-rcParams-Zuweisung und der PyCall-Grenze und vergleichen Sie dann den Wert, der das PGF-Backend von Matplotlib erreicht, mit dem funktionierenden Python-Beispiel und dem hier gezeigten backend_pgf.py-Traceback. Reproduzieren Sie das Beispiel und überprüfen Sie, dass das definierte LaTeX-Makro während des Renderns der Abbildung verfügbar ist und dass test.pdf erfolgreich erzeugt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
I am trying to define macros in my "pgf.preamble" so I can later change parts of the figure labels when including my figures in a LaTeX document without having to regenerate the figures. This works well in python:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use("pgf")
plt.rcParams.update({
"text.usetex": True,
"pgf.preamble": "\n".join([
r"\newcommand{\cmd}{t_a}",
])
})
x = np.linspace(0, 10, 100)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y, label=r"$\sin(x)$")
ax.legend()
ax.set_ylabel(L"$\cmd$")
fig.savefig("test.pdf")
runs and correctly puts $t_a$ into the y-label of the output PDF. In julia on the other hand:
using PyPlot
PyPlot.matplotlib.use("pgf")
rcParams = PyPlot.PyDict(PyPlot.matplotlib."rcParams")
rcParams["pgf.preamble"] = [
raw"\newcommand{\cmd}{t_a}"
]
rcParams["text.usetex"] = true
x = 0:0.1:10
y = sin.(x)
fig, ax = PyPlot.subplots()
ax.plot(x, y, label=L"$\sin(x)$")
ax.legend()
ax.set_ylabel(L"$\cmd$")
fig.savefig("test.pdf")
fails in the last line with
ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/yc20910/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'ValueError'>
ValueError("Error measuring '\\\\sffamily\\\\fontsize{10.000000}{12.000000}\\\\selectfont \\\\(\\\\displaystyle \\\\cmd\\\\)'\nLaTeX Output:\n! Undefined control sequence.\n<argument> ...00}\\selectfont \\(\\displaystyle \\cmd \n \\)\n<*> ....000000}\\selectfont \\(\\displaystyle \\cmd\\)}\n \\typeout{\\the\\wd0,\\the\\ht0...\nNo pages of output.\nTranscript written on texput.log.\n")
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/figure.py", line 3012, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 2314, in print_figure
result = print_method(
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/backends/backend_pgf.py", line 873, in print_pdf
self.print_pgf(tmppath / "figure.pgf", **kwargs)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/backends/backend_pgf.py", line 860, in print_pgf
self._print_pgf_to_fh(file, **kwargs)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 1643, in wrapper
return func(*args, **kwargs)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/backends/backend_pgf.py", line 845, in _print_pgf_to_fh
self.figure.draw(renderer)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 73, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/figure.py", line 2803, in draw
mimage._draw_list_compositing_images(
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 3082, in draw
mimage._draw_list_compositing_images(
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/axis.py", line 1172, in draw
self.label.draw(renderer)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/text.py", line 685, in draw
bbox, info, descent = self._get_layout(renderer)
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/text.py", line 317, in _get_layout
w, h, d = renderer.get_text_width_height_descent(
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/backends/backend_pgf.py", line 738, in get_text_width_height_descent
w, h, d = (LatexManager._get_cached_or_new()
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/backends/backend_pgf.py", line 334, in get_width_height_descent
return self._get_box_metrics(_escape_and_apply_props(text, prop))
File "/home/yc20910/.local/lib/python3.8/site-packages/matplotlib/backends/backend_pgf.py", line 347, in _get_box_metrics
raise ValueError("Error measuring {!r}\nLaTeX Output:\n{}"
Stacktrace:
[1] pyerr_check
@ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:75 [inlined]
[2] pyerr_check
@ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:79 [inlined]
[3] _handle_error(msg::String)
@ PyCall ~/.julia/packages/PyCall/1gn3u/src/exception.jl:96
[4] macro expansion
@ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:110 [inlined]
[5] #107
@ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 [inlined]
[6] disable_sigint
@ ./c.jl:473 [inlined]
[7] __pycall!
@ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:42 [inlined]
[8] _pycall!(ret::PyCall.PyObject, o::PyCall.PyObject, args::Tuple{String}, nargs::Int64, kw::Ptr{Nothing})
@ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:29
[9] _pycall!
@ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:11 [inlined]
[10] (::PyCall.PyObject)(args::String)
@ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:86
[11] top-level scope
@ REPL[41]:1
- Vorherrschende Sprache
- Julia
- Sterne
- 488
- Forks
- 90
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus JuliaPy/PyPlot.jl
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 30/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
-
violinplot not definedOffen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
Alle Issues in JuliaPy/PyPlot.jl
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Sienna-Platform/PowerSystemCaseBuilder.jl#239 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
JuliaPluto/Malt.jl#114 ·
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
QuantumSavory/QuantumSavory.jl#592 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
JuliaQUBO/QUBOTools.jl#136 ·