我有一个.tex文档,其中一个图由python模块生成matplotlib.我想要的是,图表尽可能好地融入文档.所以我希望图中使用的字符看起来与文档其余部分中的其他字符完全相同.
我的第一次尝试看起来像这样(matplotlibrc-file):
text.usetex : True
text.latex.preamble: \usepackage{lmodern} #Used in .tex-document
font.size : 11.0 #Same as in .tex-document
backend: PDF
Run Code Online (Sandbox Code Playgroud)
用于编译包含.texPDF输出的matplotlib内容pdflatex.
现在,输出看起来不错,但看起来有些不同,图中的字符在笔画宽度上看起来较弱.
对此最好的方法是什么?
编辑:最小例子:LaTeX输入:
\documentclass[11pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\includegraphics{./graph}
\caption{Excitation-Energy}
\label{fig:graph}
\end{figure}
\end{document}
Run Code Online (Sandbox Code Playgroud)
Python的脚本:
import matplotlib.pyplot as plt
import numpy as np
plt.plot([1,2,3,4])
plt.xlabel("Excitation-Energy")
plt.ylabel("Intensität")
plt.savefig("graph.pdf")
Run Code Online (Sandbox Code Playgroud)
PDF输出:

使用以下FastAPI后端:
from enum import Enum
from fastapi import FastAPI
class MyNumber(int, Enum):
ONE = 1
TWO = 2
THREE = 3
app = FastAPI()
@app.get("/add/{a}/{b}")
async def get_model(a: MyNumber, b: MyNumber):
return {"sum": a + b}
Run Code Online (Sandbox Code Playgroud)
当GET操作完成时:
curl -X 'GET' \
'http://127.0.0.1:8000/add/2/3' \
-H 'accept: application/json'
Run Code Online (Sandbox Code Playgroud)
返回以下内容:
{
"detail": [
{
"loc": [
"path",
"a"
],
"msg": "value is not a valid enumeration member; permitted: 1, 2, 3",
"type": "type_error.enum",
"ctx": {
"enum_values": [
1,
2, …Run Code Online (Sandbox Code Playgroud)