StatsPlots.jl icon indicating copy to clipboard operation
StatsPlots.jl copied to clipboard

Stacked groupedbar hides xtick labes for Dates

Open SirLukeSchande opened this issue 2 years ago • 3 comments

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.

SirLukeSchande avatar Apr 25 '22 15:04 SirLukeSchande

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

sethaxen avatar May 22 '22 22:05 sethaxen

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 avatar Jun 14 '24 19:06 thorek1

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)

thorek1 avatar Jun 15 '24 15:06 thorek1