I have a julia dataframe and I want to plot each column as a histogram, but only the last one is finally displayed. I'm using StatsPlot. Is there a better plotting package to use for this?
using StatsPlots
@df df histogram(:x1)
@df df histogram(:x2)
@df df histogram(:x3)
@df df histogram(:x4)
@df df histogram(:x5)
@df df histogram(:x6)
@df df histogram(:x7)
@df df histogram(:x8)
@df df histogram(:x9)
@df df histogram(:x10)
@df df histogram(:x11)
@df df histogram(:x12)
@df df histogram(:x13)
@df df histogram(:x14)
As Bogumil says in his comment it's not entirely clear what output you're after, but I can see two possible ways:
If you want to have a separate subplot for each column, you can broadcast the
histogramcall over the columns you want, example:which gives
Alternatively if you want all the histograms overlaid you can use
histogram!(note the bang) which modifies an existing plot:Note that here I've called
plot()first as everyhistogram!call overrides an existing (global) plot object, so if I had called this after creating the multiple-subplots version above the additional histograms would have been plotted on the existing previous plot.Both of these suggestions are going for brevity and might make it harder to fine tune things like labels, titles, etc. and I often find loops a clearer way to write these things, but hopefully they give you an idea of how what you're after can be done relatively easily (and without
StatsPlots, all of this is plainPlots)