我正在尝试为离散随机变量生成概率分布图。我想知道如何将 x=0 向右移动,使其位于 x=1 的位置。
正如您所看到的,使用下面的代码,上面的图表并没有做到这一点。
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{wallpaper}
\usetikzlibrary{shapes.geometric}
\usepgfplotslibrary{fillbetween}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
%axis lines=middle,
grid=major,
%ticks=none,
xmin=0,
xmax=4.2,
ymin=0,
ymax=0.55,
clip=false,
xtick={0,1,2,3,4},
xticklabels={$0$,$1$,$2$,$3$,$4$},
ytick={0,0.1,0.2,0.3,0.4,0.5},
height=10cm,
width=14cm,
%axis line style={shorten >=-10pt, shorten <=-10pt},
yticklabel style={
fill=white,
%yshift=10pt,
},
ylabel=\text{proportion},
xticklabel style={
%xshift=10pt,
fill=white
},
xlabel=\text{Number of accidents per week},
ylabel near ticks,
xlabel near ticks
%ylabel style={rotate=-90}
]
%\node[below] at (axis cs:-1.5,0) {$O$};
%\draw[fill=black](axis cs:30,35) circle (3pt);
%\draw[fill=black](axis cs:15,20) circle (3pt);
%\draw[fill=black](axis cs:25,20) circle (3pt);
%\draw[fill=black](axis cs:12,10) circle (3pt);
%\draw[fill=black](axis cs:25,22) circle (3pt);
%\draw[fill=black](axis cs:32,40) circle (3pt);
%\draw[fill=black](axis cs:50,30) circle (3pt);
%\draw[fill=black](axis cs:45,40) circle (3pt);
%\draw[fill=black](axis cs:60,50) circle (3pt);
%\draw[fill=black](axis cs:20,15) circle (3pt);
%\draw[fill=black](axis cs:15,10) circle (3pt);
%\draw[fill=black](axis cs:19,20) circle (3pt);
%\draw[fill=black](axis cs:25,20) circle (3pt);
%\draw[fill=black](axis cs:45,40) circle (3pt);
%\draw[fill=black](axis cs:50,45) circle (3pt);
%
\draw[thick,fill=gray,opacity=0.5] (axis cs: 0-0.2,0) rectangle (axis cs: 0+0.2,0.45);
\draw[thick,fill=gray,opacity=0.5] (axis cs: 1-0.2,0) rectangle (axis cs: 1+0.2,0.3);
\draw[thick,fill=gray,opacity=0.5] (axis cs: 2-0.2,0) rectangle (axis cs: 2+0.2,0.15);
\draw[thick,fill=gray,opacity=0.5] (axis cs: 3-0.2,0) rectangle (axis cs: 3+0.2,0.1);
\end{axis}
\end{tikzpicture}
\end{document}
下面的图表是我想要复制的:
先感谢您。