JuliaPlots / StatsPlots.jl

Statistical plotting recipes for Plots.jl
Other
437 stars 89 forks source link

Stacked groupedbar hides xtick labes for Dates #497

Open SirLukeSchande opened 2 years ago

SirLukeSchande commented 2 years ago

groupedbar with dates as x-labels does not show xticks when bar_position=:stack is selected.

This is the case both in gr and pgfplotsx. I haven't tested the others yet.

sethaxen commented 2 years ago

Hi, can you please provide a minimum working example demonstrating the problem?

thorek1 commented 4 months ago

here is a MWE

using StatsPlots
using Dates

# Sample Data
dates = [Date(2023, 1, 1), Date(2023, 2, 1), Date(2023, 3, 1)]
category1 = [10, 20, 30]
category2 = [15, 25, 35]

# Prepare data for grouped bar plot
data = hcat(category1, category2)

# Create the grouped bar plot with dates on the x-axis

groupedbar(dates, data, bar_position=:stack, label=["Category 1" "Category 2"])

fix would be very welcome. I am using GR backend

thorek1 commented 4 months ago

here is an imperfect workaround:

using StatsPlots
using Dates

# Sample Data
dates = [Date(2023, 1, 1), Date(2023, 2, 1), Date(2023, 3, 1)]
category1 = [10, 20, 30]
category2 = [15, 25, 35]

# Prepare data for grouped bar plot
data = hcat(category1, category2)

# Create the grouped bar plot with dates on the x-axis

groupedbar(dates, data, bar_position=:stack, label=["Category 1" "Category 2"])

groupedbar(data, bar_position=:stack, label=["Category 1" "Category 2"], xformatter= x-> begin println(x)
string(dates[min(ceil(Int,x),length(dates))])
end)