Pgfplots:具有受限域的条形图中的阴影

Pgfplots:具有受限域的条形图中的阴影

我有以下代码,可以绘制 pgf 条形图。我可以为其中一个条形图添加阴影。但是,对于另一个带有brokeny 条形图的图,我无法添加阴影,因为 pdflatex 会抛出dimension too large错误。我不知道如何解决这个问题。

另外,有人能给我一些关于如何增加两个条之间的间距的提示吗?ybar=2pt会改变每个解决方案或点中两个条之间的距离。但是,我不想改变这个距离。抱歉,如果我解释得不清楚。我在下面添加了图片。箭头显示我想要增加的距离。

在此处输入图片描述

谢谢 !

\documentclass[tikz,border=5pt]{standalone}

\usepackage[T1]{fontenc}
\usepackage[oldstylenums]{kpfonts}
\usepackage{microtype}
\usepackage{pifont}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{pgf}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}

\usepackage{tikz}
\usetikzlibrary{arrows,automata,calc,shapes, positioning,shadows,shadows.blur,shapes.geometric}

\begin{document}
\definecolor{col1}{RGB}{204, 204, 154}
\definecolor{col2}{RGB}{136, 136, 136}
\pgfplotsset{compat=newest}
\pgfplotsset{major grid style={gray!50}}

\begin{tikzpicture}
    \begin{axis}[
        every axis plot post/.style={/pgf/number format/fixed},
            bar width=4pt,
            xtick=data,
            xticklabels = {Jpeg Dec., BeamFormer, Insertion Sort, Merge Sort, Radix Sort, Dct1, Dct2, Dct3, Dct4, Dct5, Dct6, Dct7, Dct8, DctCoarse, DctFine, Comp. count, Matrix Mult., Fft},
        x tick label style={rotate=45, anchor=north east, inner sep=0mm,font=\tiny,major tick length=0pt},
        y tick label style={font=\tiny,major tick length=0pt},
        xticklabel shift={.1cm},
        ybar=1pt,
        xmin=-1,
        xmax=18,
        ymin=0,
        ymax=100,
        ymajorgrids,
        restrict y to domain*=0:105,
        visualization depends on=rawy\as\rawy,
        after end axis/.code={ % Draw line indicating break
                    \draw [ultra thick, white, decoration={snake, amplitude=1pt}, decorate] (rel axis cs:0,1.02) -- (rel axis cs:1,1.02);
                            },
        every node near coord/.style={font=\tiny,rotate=90,yshift=-0.1cm,xshift=0.1cm},
        axis lines*=none,
        axis line style={ultra thin,white},
        clip=false,
        legend columns=2,
        legend style={
        ultra thin,
    append after command={
    \pgfextra{
      \draw[draw=none,
      drop shadow={fill=black, opacity=0.5, shadow xshift=2pt, shadow yshift=-2pt}]
        (\tikzlastnode.south west)rectangle(\tikzlastnode.north east);
      }   
      },  
  }]  
    \addplot[draw=none,fill=col1, draw opacity=0,area legend,nodes near coords={\pgfmathprintnumber{\rawy}}] table[x=Number,y=Pareto] {errorPlot.csv};
    \addplot[draw=none,fill=col2, draw opacity=0,area legend,blur shadow={shadow yshift=0pt, shadow xshift=1pt}] table[x=Number,y=Max-Latency-Error] {errorPlot.csv};
     \legend{\#Solutions, \%error}
\end{axis}
\end{tikzpicture}
\end{document}

errorPlot.csv 文件如下 -

Number  Pareto  Max-Latency-Error
0   25  8
1   155 15
2   7   15
3   37  16
4   6   15
5   4   3
6   8   8
7   4   10
8   8   7
9   8   14
10  24  19
11  7   12
12  10  11
13  3   6
14  6   22
15  4   27
16  8   14
17  8   8

答案1

解决了条形间距问题,坐标附近的节点放置得更好、更充分,并用阴影替换了模糊阴影。

在此处输入图片描述

\documentclass[tikz,border=5pt]{standalone}

\usepackage[T1]{fontenc}
\usepackage[oldstylenums]{kpfonts}
\usepackage{microtype}
\usepackage{pifont}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{pgf}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}

\usepackage{tikz}
\usetikzlibrary{arrows,automata,calc,shapes, positioning,shadows,shadows.blur,shapes.geometric}

\begin{document}
\definecolor{col1}{RGB}{204, 204, 154}
\definecolor{col2}{RGB}{136, 136, 136}
\pgfplotsset{compat=newest}
\pgfplotsset{major grid style={gray!50}}


\begin{tikzpicture}
    \begin{axis}[
    width=10cm,nodes near coords,
    nodes near coords align={vertical},
        every axis plot post/.style={/pgf/number format/fixed},
            bar width=4pt,
            xtick=data,
            xticklabels = {Jpeg Dec., BeamFormer, Insertion Sort, Merge Sort, Radix Sort, Dct1, Dct2, Dct3, Dct4, Dct5, Dct6, Dct7, Dct8, DctCoarse, DctFine, Comp. count, Matrix Mult., Fft},
        x tick label style={rotate=45, anchor=north east, inner sep=0mm,font=\tiny,major tick length=0pt},
        y tick label style={font=\tiny,major tick length=0pt},
        xticklabel shift={.1cm},
        ybar=1pt,
        xmin=-1,
        xmax=18,
        ymin=0,
        ymax=100,
        ymajorgrids,
        restrict y to domain*=0:105,
        visualization depends on=rawy\as\rawy,
        after end axis/.code={ % Draw line indicating break
            \draw [ultra thick, white, decoration={snake, amplitude=1pt}, decorate] (rel axis cs:0,1.02) -- (rel axis cs:1,1.02);},
        axis lines*=none,
        axis line style={ultra thin,white},
        clip=false,
        legend columns=2,
        legend style={
        ultra thin,
    append after command={
    \pgfextra{
      \draw[draw=none,
      drop shadow={fill=black, opacity=0.5, shadow xshift=2pt, shadow yshift=-2pt}]
        (\tikzlastnode.south west)rectangle(\tikzlastnode.north east);
      }   
      },  
  }]  

    \addplot[draw=none,fill=col1, draw opacity=0,area legend,
    every node near coord/.style={font=\tiny,right,xshift=-2.5pt,rotate=90},
    drop shadow={shadow yshift=1pt, shadow xshift=1pt},
    nodes near coords={\pgfmathprintnumber{\rawy}}
    ] table[x=Number,y=Pareto] {errorPlot.csv};

    \addplot[draw=none,fill=col2, draw opacity=0,area legend,
    every node near coord/.style={font=\tiny,right,xshift=2.5pt,rotate=90},
   drop shadow={shadow yshift=1pt, shadow xshift=1pt}
   ]
     table[x=Number,y=Max-Latency-Error] {errorPlot.csv};

      \legend{\#Solutions, \%error};
\end{axis}
\end{tikzpicture}
\end{document}

相关内容