JuliaTeX / PGFPlots.jl

This library uses the LaTeX package pgfplots to produce plots.
Other
188 stars 36 forks source link

BarChart Not Working Properly #173

Closed chelseas closed 3 years ago

chelseas commented 3 years ago

fig = PGFPlots.Axis() push!(fig, PGFPlots.Plots.BarChart([1,2])) PGFPlots.save("test_bar.pdf", fig)

produces

image
mirkobunse commented 3 years ago

Looks like PGFPlots does not add the ybar option to the axis:

julia> println(tikzCode(fig))

\begin{axis}
\addplot+ coordinates {
  (1, 1)
  (2, 2)
};
\end{axis}
mykelk commented 3 years ago

You can try this: image The issue with the original code is that fig = PGFPlots.Axis() creates an axis with no properties, and to get this kind of axis plot, the ybar property of the axis needs to be set.

chelseas commented 3 years ago

The problem with this solution is that I would like to make a grouped bar chart by pushing multiple BarCharts onto a single Axis. One solution is to manually set ybar in the latex code but is there another solution?

mykelk commented 3 years ago

You can create the Axis using my method with the first bar chart, and then push on additional bar charts to that axis.

chelseas commented 3 years ago

Your method returns an object of type PGFPlots.Plots.BarChart but I'm guessing perhaps there's some way to extract the associated Axis object?

mykelk commented 3 years ago

I think you can do this: image