question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Grouped bar charts with grid

See original GitHub issue

I’m trying to produce a grouped bar chart, with horizontal grid lines turned on. Starting from the grouped bar chart example in the altair tutorials, I turned on the grid on the Y axis, as follows:

Chart(population, transform=t).mark_bar().encode(
    X('gender:N', axis=False, scale=Scale(bandSize=6)),
    Y('sum(people):Q', axis=Axis(grid=True)),
    Color('gender:N', scale=Scale(range=["#FF9800", "#03A9F4"])),
    Column('age:O', axis=Axis(orient='bottom'))
).configure(
    facet=FacetConfig(cell=CellConfig(strokeWidth=0, height=250))
)

However, this causes the grid lines to be interrupted between groups. How can we make the grid lines go across group columns?

vega 1

Thanks,

–nico

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Mar 8, 2021

Use the spacing argument to configure_facet; see https://altair-viz.github.io/gallery/us_population_over_time.html

1reaction
jakevdpcommented, Oct 14, 2016

You can set the padding attribute within the scale; for example:

from altair import *
population = load_dataset('population')

Chart(population).mark_bar().encode(
    X('sex:N', axis=False, scale=Scale(bandSize=6)),
    Y('sum(people):Q', axis=Axis(grid=True)),
    Color('sex:N', scale=Scale(range=["#FF9800", "#03A9F4"])),
    Column('age:O', axis=Axis(orient='bottom'), scale=Scale(padding=0))
).configure_facet_cell(
    strokeWidth=0, height=250
)

vega

The result looks a bit different than yours because I didn’t apply any transform.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grid of clustered/grouped barplots - bioST@TS
In this tutorial, we will see how to make a grid of clustered/ grouped bar plots using facet_wrap() . Such a grid may...
Read more >
Grouped bar charts with grid lines
I'm trying to produce a grouped bar chart, with horizontal grid lines turned on. Starting from the grouped bar chart example in the...
Read more >
Grouped bar chart with labels — Matplotlib 3.6.2 documentation
This example shows a how to create a grouped bar chart and how to annotate bars with labels. ... The use of the...
Read more >
Create a grouped bar plot in Matplotlib - GeeksforGeeks
A bar chart is a great way to compare categorical data across one or two dimensions. More often than not, it's more interesting...
Read more >
Customize grid lines in D3 grouped bar chart - Stack Overflow
I am new with D3 and I am trying to build a grouped bar chart using D3. I need my grid lines on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found