修改散点图中的某些特征

修改散点图中的某些特征

我想要对散点图进行以下修改。

标题应排版为两行。

我希望每个轴上都有一个中断,表示从 0 开始跳过。(当我上初中时,我们使用两条“平行”波浪线。)

0应该放在情节的左下角。

删除年份中的逗号。

我也有一些疑问。为什么图是用蓝色绘制的?每个点的直径是多少?我该如何使连接点的线变成虚线并以不同的蓝色绘制?

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}



\begin{tikzpicture}

\begin{axis}[grid=major, title=\textbf{Population of Pittsford in \boldmath$19^{\mathrm{th}}$ Century\unboldmath},
    ylabel = Population (in thousands),
    xlabel = Year,
    xmax=1900]

\addplot plot coordinates{(1800,1.1) (1810,1) (1820,0.9) (1830,1.2) (1840,1.5) (1850,1.5) (1860,1.5) (1870,1.7) (1880,1.75) (1890,1.75) (1900,1.9)};
\coordinate (Bottom Left) at (axis cs:1800,0);
\coordinate (Bottom Right) at ($(Bottom Left) + (axis direction cs:100,0)$);
\draw (Bottom Left) -- (Bottom Right);
\coordinate (Top Left) at ($(Bottom Left) + (axis direction cs:0,0.1)$);
\coordinate (Top Right) at ($(Top Left) + (axis direction cs:20,0)$);
\draw[red,thick] (Top Left) -- (Top Right);

\end{axis}

\end{tikzpicture}


\end{document}

答案1

首先,我认为你应该采用 percusse 的解决方案。但根据你的明确要求,你可以这样做:

  1. 我不知道如何重新定义axis x discontinuityaxis y discontinuity使用更小的线条或仅在左侧和底部使用它们(而不是右侧和顶部也使用它们)。所以我根本不使用它们。
  2. 您不需要刻度标记,因为您已经有了grid=major。所以我添加了ytick style = {draw=none}, xtick style = {draw=none}以摆脱它们。
  3. 至于标签的旋转:你不需要tick label style = {}在另一个标签内tick label style = {}。只需选择yticklabel style = {font=\tiny, fill=white, rotate=0}, xticklabel style = {font=\tiny, fill=white, rotate=-45}
  4. 现在来说说不连续性:我把它们放在你的图的顶部,因为 这当然是一种不好的做法,但它可以让它看起来像你想要的那样。此外,它还需要大量的反复试验才能找到和的extra ticks“正确”值:xshiftyshift

代码:

\documentclass[tikz,border=2mm]{standalone}
\usepackage{pgfplots} 
\pgfplotsset{compat=newest}

\def\discon{$\wr\!\!\!\wr$}

\begin{document} 
    \begin{tikzpicture} 
        \begin{axis}[   grid                = major,
                        /pgf/number format/1000 sep = {},
                        title               = Population of Pittsford in \\ 19\textsuperscript{th} Century,
                        title style         = {align=center,font=\bfseries},
                        ylabel              = Population (in thousands),
                        xlabel              = Year,
                        xmin                = 1790,
                        xmax                = 1900,
                        xtick               = {1800,1810,...,1900},
                        ytick style         = {draw=none},
                        xtick style         = {draw=none},
                        yticklabel style    = {font=\tiny, fill=white},
                        xticklabel style    = {font=\tiny, fill=white, rotate=-45},
                        ymin                = 0.6,
                        ymax                = 2, 
                        ytick               = {0.8, 1, ..., 2},
                        extra x ticks       = {1792},
                        extra x tick style  = {grid=none, xticklabel style={yshift=1.3mm, rotate=45, inner sep=.5pt}},
                        extra x tick labels = {\discon},
                        extra y ticks       = {0.7},
                        extra y tick style  = {grid=none, yticklabel style={xshift=1.1mm, rotate=90, inner sep=.5pt}},
                        extra y tick labels = {\discon}]
            \addplot plot coordinates{(1800,1.1) (1810,1) (1820,0.9) (1830,1.2) (1840,1.5) (1850,1.5) (1860,1.5) (1870,1.7) (1880,1.75) (1890,1.75) (1900,1.9)};
        \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

编辑:对评论的答复:

  1. \def\discon{$\wr\!\!\!\wr$}:这定义了一个新命令\discon,我将其用作不连续性的符号。它是使用两个\wr(在数学模式下)构建的。\!(负薄空间(通常为四边形的 -1/6))负责处理这两个之间的间距\wr
  2. 关于旋转:我不知道为什么当你把 放在tick label style里面时,旋转会发生tick label style在 上面。但这是错误的语法,所以只需使用正确的语法,把 放在 rotate里面 1tick label style而不是 2 即可。

答案2

y 轴不需要任何不连续性,因为它已经接近零了。另外,两个轴上的不连续性表明原点无论如何都不相关。

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[/pgf/number format/1000 sep={}]
\begin{axis}[axis y line=left,axis x line=bottom,width=10cm,height=5cm,
    grid=major, 
    title=Population of Pittsford in\\ 19\textsuperscript{th} Century,
    title style={align=center,font=\bfseries},
    ylabel = Population (in thousands),
    xlabel = Year,
    xmax=1900,xmin=1790,xtick={1800,1810,...,1900},
    ymin=0,ymax=2.5,
    axis x discontinuity=parallel,
]

\addplot+[draw=blue!50,mark size=1pt] plot coordinates{
(1800,1.1) (1810,1) (1820,0.9) (1830,1.2) 
(1840,1.5) (1850,1.5) (1860,1.5) (1870,1.7) 
(1880,1.75) (1890,1.75) (1900,1.9)};
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容