1

I'm trying to plot a logarithmic histogram with bins based on orders of magnitude.

I've got this source:

\documentclass[twocolumn, a4paper]{article}
\usepackage{pgfplots}
\begin{document}

\begin{figure}
\begin{tikzpicture}
\begin{semilogxaxis}[xlabel=Number of Active Satellites, ylabel=Frequency]
\addplot[color=red, ybar interval]
plot coordinates {(5.5,856) (55,110) (550,14) (5500,122)};
\end{semilogxaxis}
\end{tikzpicture}
\caption{Number of active satellites controlled by operator}
\label{fig:satellitesbyoperatorhisto}
\end{figure}

\end{document}

Which produces this output:

PgfPlot

You can see that the last bar (1000 <= x < 10000) seems to be missing.

Why?

6
  • Four points give three intervals. There are three bars. -nothing is missing. Commented Feb 4, 2023 at 16:25
  • Sorry what? Am I totally misunderstanding how pgfplots bar charts work... Do you not just define the centre-point of the bar? That would explain why everything looks a bit squiff... Commented Feb 4, 2023 at 16:25
  • I am not at a computer right now, so I can not test. -also your code can not compile in its current state. Please add everything needed to compile. Try to remove the option ybar interval and add ybar. Commented Feb 4, 2023 at 16:32
  • I need ybar interval because it's a histogram. If I just use ybar I get the 4 bars but with unwanted gaps between them. I think I may have misunderstood how ybar interval works Commented Feb 4, 2023 at 16:45
  • In the package documentation is stated: There is one conceptional difference when working with intervals: an interval is defined by two coordinates. Since ybar has one value for each interval, the ith bar is defined by 1. the y value of the ith coordinates, 2. the x value of the ith coordinate as left interval boundary, 3. the x value of the (i + 1)th coordinate as right interval boundary. Consequently, there is one coordinate too much: the last coordinate will only be used to determine the interval width; its y value doesn’t influence the bar appearance..
    – Zarko
    Commented Feb 4, 2023 at 19:55

1 Answer 1

2

Let extend me my comment to an answer.

In the package documentation, page 87, is about ybar interval stated:

There is one conceptional difference when working with intervals: an interval is defined by two coordinates. Since ybar has one value for each interval, the ith bar is defined by

  1. the y value of the ith coordinates,
  2. the x value of the ith coordinate as left interval boundary,
  3. the x value of the (i + 1)th coordinate as right interval boundary.

Consequently, there is one coordinate too much: the last coordinate will only be used to determine the interval width; its y value doesn’t influence the bar appearance.

Regarding this, your image, that in case should have four interval bars need additional coordinate for determining last interval. In it is important x-coordinate, , y can be doomy:

\documentclass[twocolumn, a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{figure}
\begin{tikzpicture}
\begin{semilogxaxis}[xlabel=Number of Active Satellites, ylabel=Frequency]
\addplot[color=red, ybar interval]
plot coordinates {(5.5,856) (55,110) (550,14) (5500,122) 
                   (55000,0)};  % <--- dummy y vale, just determine last interwal width
\end{semilogxaxis}
\end{tikzpicture}
\caption{Number of active satellites controlled by operator}
\label{fig:satellitesbyoperatorhisto}
\end{figure}

\end{document}

enter image description here

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .