Импорт pgf в LaTeX не работает из-за шрифта осей matplotlibPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Импорт pgf в LaTeX не работает из-за шрифта осей matplotlib

Сообщение Anonymous »

Я рисовал как обычно, но после сохранения одного из моих графиков в формате PGF и последующей компиляции LaTeX он больше не работал. Насколько мне известно, я ничего не менял, так получилось, что он перестал работать.
Код, который я использую для создания примера графика, следующий:< /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
Конечно, я могу их закомментировать, но тогда (что более очевидно для других графиков) оси будут набраны странным шрифтом, и если у меня будет другой, скажем, логарифмический масштаб, это не будет выглядеть так: 10^{-21}, как в латексе, и шрифт тоже другой.
Я получаю следующие коды ошибок в латексе:

Код: Выделить всё

! 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://tex.stackexchange.com/q/718364/36296
в надежде найти решение

Подробнее здесь: https://stackoverflow.com/questions/785 ... -axes-font
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Экспорт Matplotlib в формате pgf: supylabel смещен
    Anonymous » » в форуме Python
    0 Ответы
    14 Просмотры
    Последнее сообщение Anonymous
  • Класс осей - явно устанавливает размер (ширину/высоту) осей в заданных единицах.
    Anonymous » » в форуме Python
    0 Ответы
    56 Просмотры
    Последнее сообщение Anonymous
  • Размер шрифта CSS: установите его для *, так как размер шрифта кратен rem, а размер шрифта тела умножается вдвое.
    Anonymous » » в форуме CSS
    0 Ответы
    345 Просмотры
    Последнее сообщение Anonymous
  • Как установить размер шрифта заголовка рисунка и меток осей?
    Anonymous » » в форуме Python
    0 Ответы
    14 Просмотры
    Последнее сообщение Anonymous
  • Matplotlib + Latex Rendering/winx(): неправильный шрифт на вторичной оси Y?
    Гость » » в форуме Python
    0 Ответы
    29 Просмотры
    Последнее сообщение Гость

Вернуться в «Python»