我正在使用 pdf 图创建颜色条。结果在 TexStudio 查看器和 pdf 文件中不匹配。(下图:左侧 TexStudio 预览,右侧 pdf 输出)
我的代码:
\usepackage[cmyk]{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%colorbar sampled,colorbar style={samples=200},
%colormap access=piecewise constant,
colormap/viridis,xmin=0, xmax=3,ymin=-2.5,ymax=5, width=1.1\textwidth,
height=0.75\textwidth,white, xtick=\empty, ytick=\empty, colorbar
,colorbar style={height=0.25*\pgfkeysvalueof{/pgfplots/parent axis width}}]
\end{axis}
\end{tikzpicture}
\end{document}
有人有想法吗?
答案1
终端输出和原始代码的日志文件显示以下消息(PGF/TikZ 3.0.1a):
Package pgfplots Warning: colorbar remark: The colormap 'viridis' has a CMYK co
lorspace which is not (yet) supported by PGF. I switched colorbar styles automa
tically to the visually equivalent 'colorbar sampled={surf,shader=interp}' to g
enerate a proper CMYK colorbar. This has less support in some previewers. Use \
pgfplotscolorbarCMYKworkaroundfalse to disable this improvement. [This message
won't be replicated for 'viridis'] on input line 15.
根据那里给出的建议添加\pgfplotscolorbarCMYKworkaroundfalse
:
\documentclass{article}
\usepackage[cmyk]{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotscolorbarCMYKworkaroundfalse
\pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%colorbar sampled,colorbar style={samples=200},
%colormap access=piecewise constant,
colormap/viridis,xmin=0, xmax=3,ymin=-2.5,ymax=5, width=1.1\textwidth,
height=0.75\textwidth,white, xtick=\empty, ytick=\empty, colorbar
,colorbar style={height=0.25*\pgfkeysvalueof{/pgfplots/parent axis width}}]
\end{axis}
\end{tikzpicture}
\end{document}
这会导致日志中出现以下消息:
Package pgfplots Warning: I am about to convert colormap 'viridis' from cmyk to
rgb (which might be lossy). Perhaps the choice 'colorbar sampled={surf,shader=
interp}' yields better results since it supports cmyk. on input line 16.
然而,Evince 中的输出符合要求:
请注意,PGF 中的 CMYK 支持在 3.1.3 版本中得到了改进,因此升级足以解决您的问题。