Код, который я использую для создания примера графика, следующий:< /p>
Код: Выделить всё
import matplotlib . pyplot as plt
import numpy as np
from pathlib import Path
import matplotlib .cm as cm
import tikzplotlib
import matplotlib as mpl
mpl.rcParams['mathtext.fontset'] = 'cm' # Latex font
mpl.rcParams['font.family'] = 'serif'
mpl.rcParams['font.serif'] = ['cmr10']
mpl.rcParams['axes.formatter.use_mathtext'] = True
# Erzeuge eine Liste von x-Werten
x = np.linspace(-5, 10, 100)
a= [2,8,8,2]
b=[2,2,8,2]
U_1=2
U_2=8
I_1=2
I_2=8
# Berechne die entsprechenden y-Werte für die Funktion y = x
y = x
# Plotte die Funktion
plt.plot(x, y)
plt.plot(a,b, color = 'crimson', marker='', linestyle='dashed')
plt.plot(U_1,I_1, color = 'green', marker='x', linestyle='',label='$(U_{1}, I_{1})$', markersize=14)
plt.plot(U_2,I_2, color = 'orange', marker='x', linestyle='',label='$(U_{1}, I_{2})$', markersize=14)
plt.plot(U_2,I_1, color = 'purple', marker='x', linestyle='',label='$(U_{2}, I_{2})$', markersize=14)
# Beschriftungen für die Achsen hinzufügen
plt.xlabel('$I$ / arbitrary units')
plt.ylabel('$U$ / arbitrary units')
# Titel für den Plot hinzufügen
plt.title('Beispiel Fit')
plt.legend(loc='upper left')
# Grid hinzufügen
plt.grid(True)
# Den Plot anzeigen
plt.savefig('example.pgf', format='pgf', bbox_inches='tight', pad_inches = 0)
plt.show()
Код: Выделить всё
mpl.rcParams['font.serif'] = ['cmr10']
mpl.rcParams['axes.formatter.use_mathtext'] = True
Я получаю следующие коды ошибок в латексе:
Код: Выделить всё
! Undefined control sequence.
\mathdefault
l.109 ...\catcode`\%=\active\def%{\%}$\mathdefault
{\ensuremath{-}4}$}}%
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
! Undefined control sequence.
\mathdefault
l.147 ...\catcode`\%=\active\def%{\%}$\mathdefault
{\ensuremath{-}2}$}}%
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
! Undefined control sequence.
\mathdefault
l.185 ...\catcode`\%=\active\def%{\%}$\mathdefault
{0}$}}%
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
! Undefined control sequence.
\mathdefault
l.223 ...\catcode`\%=\active\def%{\%}$\mathdefault
{2}$}}%
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
...
в надежде найти решение
Подробнее здесь: https://stackoverflow.com/questions/785 ... -axes-font