生成这两张图的latex代码

생성일: 2026년 10월 9일

답변에 사용된 모델 GPT-5.6 Thinking by Chat01

질문

image.png
image.png

生成这两张图的latex代码

사고

编写 LaTeX 图形

我正在用 TikZ + PGFPlots 重绘两张图。由于原始数据没有提供,折线图和柱状图中的数值需要按图片视觉效果近似填写;替换数据表即可获得精确结果。

编写了 LaTeX 图形

Worked for 1m 31s

답변

可以。下面用 TikZ + PGFPlots 复刻这两张图。第二张图的柱高可以直接按图中标出的数值精确重画;第一张图左侧柱状图按图中的 reduction 百分比构造,右侧折线由于截图没有原始数据,我按曲线形状做了近似数据,版式、颜色、marker 和趋势会比较接近原图。

先在导言区加入:

latex
\usepackage{graphicx} \usepackage{xcolor} \usepackage{pgfplots} \usepgfplotslibrary{groupplots} \usetikzlibrary{plotmarks,positioning} \pgfplotsset{compat=1.18}

图 1:六组误差柱状图 + 六个时序子图

latex
% ========================= % Figure 1 % ========================= % Colors \definecolor{gdcolor}{RGB}{112,170,162} \definecolor{pjmcolor}{RGB}{166,203,82} \definecolor{txcolor}{RGB}{235,202,111} \definecolor{indiacolor}{RGB}{139,158,207} \definecolor{hunancolor}{RGB}{222,170,174} \definecolor{europe_color}{RGB}{222,148,100} \definecolor{baselinered}{RGB}{185,82,68} \definecolor{proposedblue}{RGB}{49,96,158} \definecolor{reduceRed}{RGB}{181,75,61} % Approximate time-series data reconstructed from the figure \pgfplotstableread{ t g1 b1 p1 g2 b2 p2 g3 b3 p3 0 .34 .39 .36 .32 .35 .31 .36 .38 .35 1 .31 .35 .34 .28 .32 .27 .33 .36 .32 2 .30 .34 .33 .27 .31 .26 .31 .35 .31 3 .33 .36 .35 .30 .35 .30 .33 .35 .34 4 .36 .38 .39 .36 .36 .35 .38 .40 .38 5 .42 .44 .43 .70 .46 .69 .55 .55 .56 6 .52 .55 .53 .80 .61 .81 .70 .71 .71 7 .60 .63 .61 .82 .65 .82 .78 .79 .79 8 .64 .66 .65 .81 .66 .80 .81 .80 .82 9 .67 .67 .68 .81 .68 .80 .82 .81 .83 10 .68 .70 .69 .79 .64 .78 .81 .81 .82 11 .64 .64 .65 .75 .60 .74 .79 .79 .80 12 .59 .60 .60 .70 .57 .70 .75 .75 .76 13 .54 .56 .55 .67 .55 .66 .71 .72 .71 14 .49 .53 .50 .70 .58 .69 .68 .69 .68 15 .46 .53 .49 .76 .61 .75 .66 .67 .67 16 .52 .65 .56 .86 .68 .86 .74 .75 .75 17 .61 .66 .60 .87 .69 .88 .83 .82 .84 18 .70 .70 .72 .83 .69 .85 .86 .85 .86 19 .73 .71 .75 .81 .67 .82 .82 .83 .81 20 .72 .71 .74 .80 .66 .79 .78 .80 .78 21 .70 .68 .72 .70 .58 .69 .67 .68 .66 22 .60 .60 .62 .56 .49 .54 .52 .54 .51 23 .49 .48 .50 .43 .38 .41 .39 .41 .38 }\timeseriesdata \tikzset{ gt/.style={ black, dashed, line width=0.9pt, mark=square, mark size=1.7pt, mark options={fill=white,line width=0.7pt} }, baseline/.style={ baselinered, line width=1pt, mark=triangle, mark size=2pt, mark options={rotate=180,fill=white,line width=0.8pt} }, proposed/.style={ proposedblue, line width=1.1pt, mark=star, mark size=1.8pt } } \begin{figure*}[t] \centering \resizebox{\textwidth}{!}{% \begin{tikzpicture} % ============================================================ % Panel b: bar charts % ============================================================ \begin{scope}[xshift=0cm] \begin{groupplot}[ group style={ group name=bars, group size=3 by 2, horizontal sep=0.45cm, vertical sep=0.45cm }, width=3.25cm, height=3.15cm, ymin=0, ymax=0.095, xmin=-0.65, xmax=1.65, xtick={0,1}, xticklabels={nMAE,nRMSE}, ytick={0,0.02,0.04,0.06,0.08}, tick align=outside, axis x line*=bottom, axis y line*=left, tick label style={font=\small}, title style={font=\bfseries\small,yshift=-2pt}, ylabel style={font=\small}, legend style={ draw=none, fill=none, font=\scriptsize, row sep=-2pt, at={(0.98,0.98)}, anchor=north east } ] % ---------------- Guangdong ---------------- \nextgroupplot[ title={Guangdong}, ylabel={Forecasting Error}, xticklabels=\empty ] % Reference/baseline bars \addplot[ ybar, bar width=13pt, fill=gdcolor!35, draw=gray, dashed, line width=1pt ] coordinates { (0,0.03730) (1,0.05191) }; % Proposed \addplot[ ybar, bar width=13pt, fill=gdcolor, draw=black, line width=1pt ] coordinates { (0,0.0260) (1,0.0340) }; \addlegendimage{area legend,fill=gdcolor,draw=black} \addlegendentry{Proposed} \addlegendimage{ area legend, fill=gdcolor!35, draw=gray, dashed } \addlegendentry{Reduction} \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:0,0.0373) {30.3\%$\downarrow$}; \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:1,0.05191) {34.5\%$\downarrow$}; % ---------------- PJM ---------------- \nextgroupplot[ title={PJM}, yticklabels=\empty, xticklabels=\empty ] \addplot[ ybar, bar width=13pt, fill=pjmcolor!35, draw=gray, dashed, line width=1pt ] coordinates { (0,0.03769) (1,0.05237) }; \addplot[ ybar, bar width=13pt, fill=pjmcolor, draw=black, line width=1pt ] coordinates { (0,0.0340) (1,0.0475) }; \addlegendimage{area legend,fill=pjmcolor,draw=black} \addlegendentry{Proposed} \addlegendimage{ area legend, fill=pjmcolor!35, draw=gray, dashed } \addlegendentry{Reduction} \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:0,0.03769) {9.8\%$\downarrow$}; \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:1,0.05237) {9.3\%$\downarrow$}; % ---------------- Texas ---------------- \nextgroupplot[ title={Texas}, yticklabels=\empty, xticklabels=\empty ] \addplot[ ybar, bar width=13pt, fill=txcolor!35, draw=gray, dashed, line width=1pt ] coordinates { (0,0.04475) (1,0.05534) }; \addplot[ ybar, bar width=13pt, fill=txcolor, draw=black, line width=1pt ] coordinates { (0,0.0345) (1,0.0435) }; \addlegendimage{area legend,fill=txcolor,draw=black} \addlegendentry{Proposed} \addlegendimage{ area legend, fill=txcolor!35, draw=gray, dashed } \addlegendentry{Reduction} \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:0,0.04475) {22.9\%$\downarrow$}; \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:1,0.05534) {21.4\%$\downarrow$}; % ---------------- India ---------------- \nextgroupplot[ title={India}, ylabel={Forecasting Error} ] \addplot[ ybar, bar width=13pt, fill=indiacolor!35, draw=gray, dashed, line width=1pt ] coordinates { (0,0.03090) (1,0.03784) }; \addplot[ ybar, bar width=13pt, fill=indiacolor, draw=black, line width=1pt ] coordinates { (0,0.0275) (1,0.0350) }; \addlegendimage{area legend,fill=indiacolor,draw=black} \addlegendentry{Proposed} \addlegendimage{ area legend, fill=indiacolor!35, draw=gray, dashed } \addlegendentry{Reduction} \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:0,0.03090) {11.0\%$\downarrow$}; \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:1,0.03784) {7.5\%$\downarrow$}; % ---------------- Hunan ---------------- \nextgroupplot[ title={Hunan}, yticklabels=\empty ] \addplot[ ybar, bar width=13pt, fill=hunancolor!35, draw=gray, dashed, line width=1pt ] coordinates { (0,0.03280) (1,0.04139) }; \addplot[ ybar, bar width=13pt, fill=hunancolor, draw=black, line width=1pt ] coordinates { (0,0.0285) (1,0.0375) }; \addlegendimage{area legend,fill=hunancolor,draw=black} \addlegendentry{Proposed} \addlegendimage{ area legend, fill=hunancolor!35, draw=gray, dashed } \addlegendentry{Reduction} \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:0,0.03280) {13.1\%$\downarrow$}; \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:1,0.04139) {9.4\%$\downarrow$}; % ---------------- Europe ---------------- \nextgroupplot[ title={Europe}, yticklabels=\empty ] \addplot[ ybar, bar width=13pt, fill=europe_color!35, draw=gray, dashed, line width=1pt ] coordinates { (0,0.03835) (1,0.04603) }; \addplot[ ybar, bar width=13pt, fill=europe_color, draw=black, line width=1pt ] coordinates { (0,0.0255) (1,0.0325) }; \addlegendimage{area legend,fill=europe_color,draw=black} \addlegendentry{Proposed} \addlegendimage{ area legend, fill=europe_color!35, draw=gray, dashed } \addlegendentry{Reduction} \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:0,0.03835) {33.5\%$\downarrow$}; \node[ font=\scriptsize, text=reduceRed, anchor=south ] at (axis cs:1,0.04603) {29.4\%$\downarrow$}; \end{groupplot} \node[ font=\bfseries\Large, anchor=south west ] at ([xshift=-0.8cm,yshift=0.15cm]bars c1r1.north west) {b}; \end{scope} % ============================================================ % Panel c: time series % ============================================================ \begin{scope}[xshift=10.9cm] \begin{groupplot}[ group style={ group name=lines, group size=3 by 2, horizontal sep=0.35cm, vertical sep=0.35cm }, width=3.25cm, height=3.15cm, xmin=0, xmax=23, xtick={0,10,20}, tick align=outside, axis x line*=bottom, axis y line*=left, grid=major, grid style={ dashed, gray!45, line width=0.5pt }, tick label style={font=\small}, label style={font=\small} ] % ---------------- top 1 ---------------- \nextgroupplot[ ymin=0.23, ymax=0.90, ytick={0.4,0.6,0.8}, ylabel={Norm. Load}, xticklabels=\empty, legend style={ draw=none, fill=none, legend columns=3, font=\small, column sep=1.0em, at={(1.62,1.15)}, anchor=south } ] \addplot[gt] table[x=t,y=g1] {\timeseriesdata}; \addlegendentry{Ground Truth} \addplot[baseline] table[x=t,y=b1] {\timeseriesdata}; \addlegendentry{Baseline} \addplot[proposed] table[x=t,y=p1] {\timeseriesdata}; \addlegendentry{Proposed} % ---------------- top 2 ---------------- \nextgroupplot[ ymin=0.23, ymax=0.90, ytick={0.4,0.6,0.8}, yticklabels=\empty, xticklabels=\empty ] \addplot[gt] table[x=t,y=g2] {\timeseriesdata}; \addplot[baseline] table[x=t,y=b2] {\timeseriesdata}; \addplot[proposed] table[x=t,y=p2] {\timeseriesdata}; % ---------------- top 3 ---------------- \nextgroupplot[ ymin=0.23, ymax=0.90, ytick={0.4,0.6,0.8}, yticklabels=\empty, xticklabels=\empty ] \addplot[gt] table[x=t,y=g3] {\timeseriesdata}; \addplot[baseline] table[x=t,y=b3] {\timeseriesdata}; \addplot[proposed] table[x=t,y=p3] {\timeseriesdata}; % ---------------- bottom 1 ---------------- \nextgroupplot[ ymin=-0.005, ymax=0.20, ytick={0,0.1,0.2}, ylabel={Deviation}, xlabel={Time Index [h]} ] \addplot[baseline] table[ x=t, y expr={abs(\thisrow{b1}-\thisrow{g1})} ] {\timeseriesdata}; \addplot[proposed] table[ x=t, y expr={abs(\thisrow{p1}-\thisrow{g1})} ] {\timeseriesdata}; % ---------------- bottom 2 ---------------- \nextgroupplot[ ymin=-0.005, ymax=0.20, ytick={0,0.1,0.2}, yticklabels=\empty, xlabel={Time Index [h]} ] \addplot[baseline] table[ x=t, y expr={abs(\thisrow{b2}-\thisrow{g2})} ] {\timeseriesdata}; \addplot[proposed] table[ x=t, y expr={abs(\thisrow{p2}-\thisrow{g2})} ] {\timeseriesdata}; % ---------------- bottom 3 ---------------- \nextgroupplot[ ymin=-0.005, ymax=0.20, ytick={0,0.1,0.2}, yticklabels=\empty, xlabel={Time Index [hour]} ] \addplot[baseline] table[ x=t, y expr={abs(\thisrow{b3}-\thisrow{g3})} ] {\timeseriesdata}; \addplot[proposed] table[ x=t, y expr={abs(\thisrow{p3}-\thisrow{g3})} ] {\timeseriesdata}; \end{groupplot} \node[ font=\bfseries\Large, anchor=south west ] at ([xshift=-0.7cm,yshift=0.15cm]lines c1r1.north west) {c}; \end{scope} \end{tikzpicture}% } \caption{ Comparison of forecasting errors and qualitative load forecasting performance under extreme weather conditions. } \label{fig:extreme_weather} \end{figure*}

这里有一个小技巧和原图比较接近:每个误差柱先画一个“完整 baseline 柱”,用淡色+虚线边框,然后再在它上面覆盖实色的 Proposed 柱,所以露出来的上半截自然就变成了图中的 Reduction 区域。


图 2:Climate / Energy / Security / Traffic 四联柱状图

这张图可以按截图上的数值直接画:

latex
% ========================= % Figure 2 % ========================= \definecolor{modelA}{RGB}{19,176,229} \definecolor{modelB}{RGB}{174,174,227} \definecolor{modelC}{RGB}{75,198,195} \definecolor{modelD}{RGB}{169,169,169} \begin{figure*}[t] \centering \resizebox{0.98\textwidth}{!}{% \begin{tikzpicture} \begin{groupplot}[ group style={ group size=4 by 1, horizontal sep=1.0cm }, width=4.6cm, height=5.0cm, xmin=0.5, xmax=4.5, xtick={1,2,3,4}, xticklabels={ Qwen2.5-7B, Qwen2.5-0.5B, GPT2, PatchTST(Uni) }, x tick label style={ rotate=28, anchor=north east, font=\small }, tick align=outside, axis x line*=bottom, axis y line*=left, axis line style={line width=0.7pt}, tick style={line width=0.7pt}, title style={ font=\bfseries\large, yshift=3pt }, nodes near coords, point meta=explicit symbolic, every node near coord/.append style={ font=\scriptsize, yshift=2pt }, clip=false ] % ================================================== % Climate % ================================================== \nextgroupplot[ title={Climate}, ylabel={MSE}, ymin=0.84, ymax=0.988, ytick={0.85,0.90,0.95}, yticklabel style={ /pgf/number format/fixed, /pgf/number format/precision=3 } ] \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelA, draw=none ] coordinates { (1,0.872) [0.872] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelB, draw=none ] coordinates { (2,0.892) [0.892] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelC, draw=none ] coordinates { (3,0.889) [0.889] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelD, draw=none ] coordinates { (4,0.977) [0.977] }; % ================================================== % Energy % ================================================== \nextgroupplot[ title={Energy}, ymin=0.211, ymax=0.294, ytick={0.22,0.24,0.26,0.28}, yticklabel style={ /pgf/number format/fixed, /pgf/number format/precision=3 } ] \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelA, draw=none ] coordinates { (1,0.229) [0.229] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelB, draw=none ] coordinates { (2,0.255) [0.255] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelC, draw=none ] coordinates { (3,0.253) [0.253] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelD, draw=none ] coordinates { (4,0.288) [0.288] }; % ================================================== % Security % ================================================== \nextgroupplot[ title={Security}, ymin=68, ymax=85.6, ytick={70,75,80,85} ] \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelA, draw=none ] coordinates { (1,71.5) [71.5] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelB, draw=none ] coordinates { (2,73.2) [73.2] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelC, draw=none ] coordinates { (3,73.1) [73.1] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelD, draw=none ] coordinates { (4,84.3) [84.3] }; % ================================================== % Traffic % ================================================== \nextgroupplot[ title={Traffic}, ymin=0.147, ymax=0.1755, ytick={0.15,0.16,0.17}, yticklabel style={ /pgf/number format/fixed, /pgf/number format/precision=3 } ] \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelA, draw=none ] coordinates { (1,0.153) [0.153] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelB, draw=none ] coordinates { (2,0.159) [0.159] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelC, draw=none ] coordinates { (3,0.162) [0.162] }; \addplot[ ybar, bar width=16pt, bar shift=0pt, fill=modelD, draw=none ] coordinates { (4,0.173) [0.173] }; \end{groupplot} \end{tikzpicture}% } \caption{ Multimodal time series forecasting results of replacing the LLM backbone. The time series backbone is fixed as PatchTST. The result is the average performance across four dataset-specific prediction horizons. } \label{fig:llm_backbone} \end{figure*}

第二张基本可以做到和截图非常接近,因为四组数值都直接写在图里了:Climate 为 0.872/0.892/0.889/0.977,Energy 为 0.229/0.255/0.253/0.288,Security 为 71.5/73.2/73.1/84.3,Traffic 为 0.153/0.159/0.162/0.173。

第一张右侧的折线部分,如果你有原论文的 Source Data / CSV / PDF 原图,我还可以把这里的近似曲线替换成真实数值,并进一步把字体大小、subplot 间距、线宽、marker 大小和原论文调到更接近 1:1。

이 Q&A 공유하기