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 Horizontal bar plot with reduced row spacing

See original GitHub issue

For the data:

    level_0     level_1  date depth  station      temp      WY    DOY
0       153  1995-11-01     4    in   ASHTON -0.600000  1996.0   32.0
1       618  1996-02-02     4    in   ASHTON -6.100000  1996.0  125.0
2       444  1995-12-29     4    in  REXBURG -0.522222  1996.0   90.0
3      2057  1997-02-17     4    in   ASHTON -0.038889  1997.0  140.0
4      2951  1997-11-14     4    in   ASHTON -0.061111  1998.0   45.0
5      3266  1998-01-16     4    in   ASHTON -0.572222  1998.0  108.0
6      3516  1998-03-07     4    in   ASHTON -0.233333  1998.0  158.0
7      4499  1998-12-20     4    in   ASHTON -0.961111  1999.0   81.0
8      4746  1999-02-08     4    in   ASHTON -0.155556  1999.0  131.0
9      4517  1998-12-24     4    in  REXBURG -3.194444  1999.0   85.0
10     4767  1999-02-12     4    in  REXBURG -2.394444  1999.0  135.0
11     7046  2000-11-13     4    in  REXBURG -0.277778  2001.0   44.0
12     8998  2002-02-11     4    in  REXBURG -0.361111  2002.0  134.0
13    10857  2003-03-04     4    in   ASHTON -0.500000  2003.0  155.0
14    10714  2003-02-08     4    in  REXBURG -1.027778  2003.0  131.0
15    12238  2004-01-04     4    in  REXBURG -0.033333  2004.0   96.0
16    13887  2004-12-27     4    in   ASHTON -0.122222  2005.0   88.0
17    13960  2005-01-08     4    in  REXBURG -0.211111  2005.0  100.0
18    14260  2005-02-27     4    in  REXBURG -1.133333  2005.0  150.0
19    15657  2006-01-02     4    in   ASHTON -0.111111  2006.0   94.0
20    15718  2006-01-12     4    in  REXBURG -0.200000  2006.0  104.0
21    16018  2006-03-03     4    in  REXBURG -0.083333  2006.0  154.0
22    17445  2007-01-11     4    in   ASHTON -0.272222  2007.0  103.0
23    17745  2007-03-02     4    in   ASHTON -0.183333  2007.0  153.0
24    17428  2007-01-08     4    in  REXBURG -0.238889  2007.0  100.0
25    17728  2007-02-27     4    in  REXBURG -0.111111  2007.0  150.0
26    20770  2008-12-18     4    in  REXBURG -0.911111  2009.0   79.0
27    21082  2009-02-08     4    in  REXBURG -0.294444  2009.0  131.0
28    22437  2009-12-07     4    in   ASHTON -6.266667  2010.0   68.0
29    22737  2010-01-26     4    in   ASHTON -0.250000  2010.0  118.0
30    22564  2009-12-28     4    in  REXBURG -0.611111  2010.0   89.0
31    24574  2011-02-12     4    in  REXBURG -0.361111  2011.0  135.0
32    26043  2011-12-30     4    in   ASHTON -0.127778  2012.0   91.0
33    26343  2012-02-18     4    in   ASHTON -0.266667  2012.0  141.0
34    26014  2011-12-25     4    in  REXBURG -3.750000  2012.0   86.0
35    26314  2012-02-13     4    in  REXBURG -0.466667  2012.0  136.0
36    27897  2013-01-19     4    in   ASHTON -0.100000  2013.0  111.0
37    27880  2013-01-16     4    in  REXBURG -0.488889  2013.0  108.0
38    29389  2013-12-10     4    in  REXBURG -0.850000  2014.0   71.0
39    29689  2014-01-29     4    in  REXBURG -2.755556  2014.0  121.0
40    31399  2015-01-25     4    in  REXBURG -0.755556  2015.0  117.0
41    34843  2017-01-21     4    in  REXBURG -0.077778  2017.0  113.0
42    36383  2018-01-18     4    in  REXBURG -0.077778  2018.0  110.0
43    36683  2018-03-09     4    in  REXBURG -0.122222  2018.0  160.0
44    38232  2018-12-11     4    in    RIRIE -0.638889  2019.0   72.0
45    38482  2019-01-30     4    in    RIRIE -0.788889  2019.0  122.0
46    39963  2019-11-26     4    in  REXBURG -0.122222  2020.0   57.0

I am trying to create a grouped horizontal bar plot, but to reduce the spacing between rows


chart = alt.Chart(df).mark_bar().encode(
    x=alt.X('DOY:O', axis = alt.Axis(title = "Day of Year (Oct 1 - Sep 30)")),
    y=alt.Y('station', axis = alt.Axis(title=None,ticks=False, labels=False)),
    color=alt.Color('station', legend = alt.Legend(title = None)),
    row = alt.Row('WY'),
)

This makes a plot that seems too large to post here. When i change width and height in .properties, the plot is becoming illegable. Looking for another way, I saw the alt.Row documentation says I can specify spacing in alt.Row, but I pass when I do:

chart = alt.Chart(df).mark_bar().encode(
    x=alt.X('DOY:O', axis = alt.Axis(title = "Day of Year (Oct 1 - Sep 30)")),
    y=alt.Y('station', axis = alt.Axis(title=None,ticks=False, labels=False)),
    color=alt.Color('station', legend = alt.Legend(title = None)),
    row = alt.Row('WY', spacing = 5),
)
chart.display()

I get the error:

SchemaValidationError: Invalid specification

        altair.vegalite.v3.schema.channels.Row, validating 'additionalProperties'

        Additional properties are not allowed ('spacing' was unexpected)
        

alt.Chart(...)

Basically, I want a grouped bar plot that doesn’t appear as if it is split into rows. Is this possible?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Feb 5, 2020

The spacing argument was added in Altair version 4.0. Update your Altair package, and you should be able to use it.

0reactions
danhamillcommented, Feb 5, 2020

found vegascope workaround in 4.0.0 in #1939

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

setting spacing between grouped bar plots in matplotlib
How can I make a grouped bar plot function that takes two parameters: the width of each bar, and the spacing between the...
Read more >
How to Adjust Your Bar Chart's Spacing in Microsoft Excel
Step 1. Right-click on any of the colored bars. In the drop-down menu, select Format Data Series. · Step 2. Reduce the Gap...
Read more >
How to Create Space Between Grouped Bar Chart in Chart js
The canvas tag, javascript, arrays and Chart JS all need to be combined to draw an eye catching bar chart or line chart....
Read more >
Graph tip - Changing the width and spacing of columns in ...
The simplest way to change the width of any object (bar, violin, etc.) or the spacing between objects is to change the total...
Read more >
A Complete Guide to Stacked Bar Charts | Tutorial by Chartio
The main cell values indicate the length of each sub-bar in the plot. Bars are built across rows: when the stacked bar chart...
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