How to plot bar chart and line chart on the same plot

I’m trying to plot a histogram of experimental data and the analytical function as a line chart (note that the histogram is not simply the line function binned) on the same plot, but the histogram bars are really narrow. How can I fix this? The plot looks like this:


My code is something like this:

Plot.plot({
            marks: [
                Plot.barY(bardata, {x: "energy", y: "flux"}),
                Plot.lineY(linedata, {x: "energy", y: "flux", stroke: "red"}),
                Plot.axisX({anchor: "bottom", tickSpacing: 10})
            ]
        })

Also, how can I make the labels on the x-axis not overlap and have a million labels?

Thank you!!

You should only use the barY mark if your x values are ordinal; it looks like you intend them to be quantitative (energy).

If your data is already binned, then you can use the rectY mark and the interval option with the binning interval (e.g., interval: 1 if you binned at unit intervals along x).

If you don’t know the binning interval, you could use the ruleX mark to draw a skinny bar. Or you could also use the areaY mark with the curve step.

If your data is not binned, then you can use the rectY mark and the binX transform to bin it and produce a histogram.

The step curve with the areaY mark worked great. Thanks!