forum icon indicating copy to clipboard operation
forum copied to clipboard

关于pgfplot绘制直方图的一个问题

Open chenxiao445566 opened this issue 2 years ago • 4 comments

\documentclass[border=3mm,tikz]{standalone}
\usepackage{pgfplots}
 \pgfplotsset{compat=1.18,
 	zhifangtu/.style={
 	axis lines =left,
 	tick align=inside,
 	yticklabel style={/pgf/number format/.cd,
 		fixed,
 		fixed zerofill,
 		precision=3},
 	area style,
 	x=0.2cm,
 	y=300cm,
 	ymin=0, ymax=0.1,
 	xmin=0, xmax=95,
 	xtick={0,10,20,30,40,50,60,70,80,90},
 	ytick={0.001,0.002,0.006,0.012,0.017,0.020,0.023},
 }
 }
\begin{document}
	\begin{tikzpicture}
		\begin{axis}[zhifangtu]
			\addplot+[ybar interval,fill=white,draw=black] plot coordinates {
				  (0, 0.001)
				  (10, 0.002) 
				  (20, 0.012) 
				  (30, 0.017) 
				  (40, 0.023) 
				  (50, 0.020)
				  (60, 0.017)
				  (70, 0.006)
				  (80, 0.002)
				  (90, 0)
			   };
		\end{axis}
	\end{tikzpicture}
\end{document}

我需要把ymax设置为0.028,但是无法编译(如果设置为0.1,又是可以编译的),然后找到原因是

yticklabel style={/pgf/number format/.cd,
 		fixed,
 		fixed zerofill,
 		precision=3},

把这段删掉,ymax=0.028是可以编译了,但我需要标签为小数,这段代码又不能删,那进一步还需如何设置?

chenxiao445566 avatar Jun 27 '22 02:06 chenxiao445566

不要在 /.style 里用 /.cd 切换 default path。pgfplots 的文档里也有这种用法,这是不够安全的。

    yticklabel style={
      /pgf/number format/fixed,
      /pgf/number format/fixed zerofill,
      /pgf/number format/precision=3
    },

非要切换 default path,需要再切回来

    yticklabel style={/pgf/number format/.cd,
      fixed,
      fixed zerofill,
      precision=3,
      /pgfplots/.cd
    },

不要只说「xxx,但是无法编译」,要提供具体的(第一处)报错信息。

muzimuzhi avatar Jun 27 '22 10:06 muzimuzhi

我用了最新的texstudio编译,假如有错误,它不报错了,那个红色的按钮一直红色(一直在编译),搞不懂!

chenxiao445566 avatar Jun 27 '22 12:06 chenxiao445566

我用了最新的texstudio编译,假如有错误,它不报错了,那个红色的按钮一直红色(一直在编译),搞不懂!

建议使用命令行编译。

SwitWu avatar Jun 27 '22 12:06 SwitWu

我用了最新的texstudio编译,假如有错误,它不报错了,那个红色的按钮一直红色(一直在编译),搞不懂!

「假如有错误,它不报错了,……」这里我没理解。有问题,可以提供新的例子。

补充:编译停不下来,那按红色按钮停下来后,log 里有报错吗?有报错的话,提供例子 + 第一条报错信息。

muzimuzhi avatar Jun 27 '22 15:06 muzimuzhi