LaTeX 条形图

发布于 2024-10-16 05:21:50 字数 455 浏览 2 评论 0原文

我正在尝试使用 LaTeX 制作条形图。 到目前为止我还没有成功,所以任何人都可以帮助我,也许可以提供最近项目的副本吗? 如何使用 pstricks 制作条形图?我希望能有最简单的解决方案,因为我最近才开始使用 TeX。

就像官方中提到的那样文档

这是我到目前为止所拥有的:

\psset{unit=0.5in}%
\begin{pspicture}(0,-0.5)(3,3)%
\readpsbardata{\data}{example1.csv}%
\psbarchart[barstyle={red,blue}]{\data}%
\end{pspicture}

I am trying to make a bar chart using LaTeX.
I've been unsuccessful so far, so can anyone help me out, perhaps with a copy of a recent project?
How can I make a bar chart with pstricks? I would appreciate the most simple solution possible because I just got started with TeX recently.

Like mentioned here in the official document

This is what I have so far:

\psset{unit=0.5in}%
\begin{pspicture}(0,-0.5)(3,3)%
\readpsbardata{\data}{example1.csv}%
\psbarchart[barstyle={red,blue}]{\data}%
\end{pspicture}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦开始←不甜 2024-10-23 05:21:50

我强烈推荐使用 PGF、TiKZ 和 PGFPlots 的神奇组合。这些工具通常被认为是 pstricks 的替代品。它们与 pdflatex 和许多其他给 pstricks 带来麻烦的工具兼容。

以下高度语义化的 TeX 源

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.4} 

\begin{document}

\begin{tikzpicture}

\begin{axis}[%
scale only axis,
width=5in,
height=4in,
xmin=-3, xmax=3,
ymin=0, ymax=1,
axis on top]
\addplot[
  ybar,
  bar width=0.102874in, 
  bar shift=0in,
  fill=red,
  draw=black] 
  plot coordinates{ 
    (-2.9,0.00022263) (-2.7,0.000682328) (-2.5,0.00193045) (-2.3,0.00504176)
    (-2.1,0.0121552) (-1.9,0.0270518) (-1.7,0.0555762) (-1.5,0.105399)
    (-1.3,0.18452) (-1.1,0.298197) (-0.9,0.444858) (-0.7,0.612626)
    (-0.5,0.778801) (-0.3,0.913931) (-0.1,0.99005) (0.1,0.99005)
    (0.3,0.913931) (0.5,0.778801) (0.7,0.612626) (0.9,0.444858) 
    (1.1,0.298197) (1.3,0.18452) (1.5,0.105399) (1.7,0.0555762)
    (1.9,0.0270518) (2.1,0.0121552) (2.3,0.00504176) (2.5,0.00193045)
    (2.7,0.000682328) (2.9,0.00022263)
  };

\end{axis}
\end{tikzpicture}

\end{document}

代码

Bar graph example

I highly recommend using the magical combination of PGF, TiKZ and PGFPlots. These tools are generally accepted as the replacements to pstricks. They are compatible with pdflatex and many other tools that give pstricks trouble.

This following highly semantic TeX-source

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.4} 

\begin{document}

\begin{tikzpicture}

\begin{axis}[%
scale only axis,
width=5in,
height=4in,
xmin=-3, xmax=3,
ymin=0, ymax=1,
axis on top]
\addplot[
  ybar,
  bar width=0.102874in, 
  bar shift=0in,
  fill=red,
  draw=black] 
  plot coordinates{ 
    (-2.9,0.00022263) (-2.7,0.000682328) (-2.5,0.00193045) (-2.3,0.00504176)
    (-2.1,0.0121552) (-1.9,0.0270518) (-1.7,0.0555762) (-1.5,0.105399)
    (-1.3,0.18452) (-1.1,0.298197) (-0.9,0.444858) (-0.7,0.612626)
    (-0.5,0.778801) (-0.3,0.913931) (-0.1,0.99005) (0.1,0.99005)
    (0.3,0.913931) (0.5,0.778801) (0.7,0.612626) (0.9,0.444858) 
    (1.1,0.298197) (1.3,0.18452) (1.5,0.105399) (1.7,0.0555762)
    (1.9,0.0270518) (2.1,0.0121552) (2.3,0.00504176) (2.5,0.00193045)
    (2.7,0.000682328) (2.9,0.00022263)
  };

\end{axis}
\end{tikzpicture}

\end{document}

Yields

Bar graph example

菩提树下叶撕阳。 2024-10-23 05:21:50

您必须使用 pst-bar 包和 pstricks 包。

\documentclass[12pt]{article}
\usepackage{pstricks}
\usepackage{pst-bar}
\usepackage{pstricks-add}
\usepackage{filecontents}

\begin{document}

\begin{filecontents*}{example1.csv}
Sun, Mon, Tue, Wed, Thu, Fri, Sat
1700, 1690, 1600, 1800, 1750, 1210, 1200
\end{filecontents*}

\psset{xunit=0.5in,yunit=0.0015in}
\begin{pspicture}(0,0)(8,2000)
\psframe[fillstyle=solid,fillcolor=black!10,linestyle=solid](0,0)
(8,2000)
\psaxes[yticksize=0 8,ticks=y,labels=y,Dx=1,Dy=500](0,0)
(0,0)(8,2000)
\readpsbardata[header=true]{\data}{example1.csv}
\psbarchart[barstyle=blue]{\data}
\end{pspicture}

\end{document}

You have to use pst-bar package and pstricks package.

\documentclass[12pt]{article}
\usepackage{pstricks}
\usepackage{pst-bar}
\usepackage{pstricks-add}
\usepackage{filecontents}

\begin{document}

\begin{filecontents*}{example1.csv}
Sun, Mon, Tue, Wed, Thu, Fri, Sat
1700, 1690, 1600, 1800, 1750, 1210, 1200
\end{filecontents*}

\psset{xunit=0.5in,yunit=0.0015in}
\begin{pspicture}(0,0)(8,2000)
\psframe[fillstyle=solid,fillcolor=black!10,linestyle=solid](0,0)
(8,2000)
\psaxes[yticksize=0 8,ticks=y,labels=y,Dx=1,Dy=500](0,0)
(0,0)(8,2000)
\readpsbardata[header=true]{\data}{example1.csv}
\psbarchart[barstyle=blue]{\data}
\end{pspicture}

\end{document}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文