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.

Domain legend gets squished when horizontal in colab vs vertical in vega-lite editor

See original GitHub issue

In colab, the legend gets squished so that the text is unreadable when there are multiple breakpoints.

Code to reproduce:

import altair as alt
from vega_datasets import data

counties = alt.topo_feature(data.us_10m.url, 'counties')
unemp_data = data.unemployment.url

alt.Chart(counties).mark_geoshape().encode(
    color=alt.Color('rate:Q',
          scale=alt.Scale(type="linear",
              domain=[.02,.02,.035,.035,.05,.05,.065,.065,.08,.08,.095,.095,.11,.11,.125,.125,.14,.14,.155,.155],
                          range=    
    ["#5e4fa2","#5e4fa2",
     "#3288bd","#3288bd",
     "#66c2a5","#66c2a5",
     "#abdda4","#abdda4",
     "#e6f598","#e6f598",
     "#fee08b","#fee08b",
     "#fdae61","#fdae61",
     "#f46d43","#f46d43",
     "#d53e4f","#d53e4f",
     "#9e0142","#9e0142"])),

).transform_lookup(
    lookup='id',
    from_=alt.LookupData(unemp_data, 'id', ['rate'])
).project(
    type='albersUsa'
).properties(
    width=500,
    height=300
)
screen shot 2018-07-04 at 12 02 13 pm

In the vega-lite editor, this gets rendered as a vertical legend.

screen shot 2018-07-04 at 12 06 56 pm
{
  "config": {"view": {"width": 400, "height": 300}},
  "data": {
    "url": "https://vega.github.io/vega-datasets/data/us-10m.json",
    "format": {"feature": "counties", "type": "topojson"}
  },
  "mark": "geoshape",
  "encoding": {
    "color": {
      "type": "quantitative",
      "field": "rate",
      "scale": {
        "domain": [
          0.02,
          0.02,
          0.035,
          0.035,
          0.05,
          0.05,
          0.065,
          0.065,
          0.08,
          0.08,
          0.095,
          0.095,
          0.11,
          0.11,
          0.125,
          0.125,
          0.14,
          0.14,
          0.155,
          0.155
        ],
        "range": [
          "#5e4fa2",
          "#5e4fa2",
          "#3288bd",
          "#3288bd",
          "#66c2a5",
          "#66c2a5",
          "#abdda4",
          "#abdda4",
          "#e6f598",
          "#e6f598",
          "#fee08b",
          "#fee08b",
          "#fdae61",
          "#fdae61",
          "#f46d43",
          "#f46d43",
          "#d53e4f",
          "#d53e4f",
          "#9e0142",
          "#9e0142"
        ],
        "type": "linear"
      }
    }
  },
  "height": 300,
  "projection": {"type": "albersUsa"},
  "transform": [
    {
      "lookup": "id",
      "from": {
        "data": {
          "url": "https://vega.github.io/vega-datasets/data/unemployment.tsv",
          "format": {"type": "tsv"}
        },
        "key": "id",
        "fields": ["rate"]
      }
    }
  ],
  "width": 500,
  "$schema": "https://vega.github.io/schema/vega-lite/v2.4.3.json"
}

Incidentally, the legend is in the vega-lite editor is unfortunately also inaccurate, which I’ve reported on the vega-lite repo: https://github.com/vega/vega-lite/issues/3981

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zanarmstrongcommented, Jul 4, 2018

Hi Jeff -

Thanks for the quick reply!

“Vega does support a threshold scale type that will provide a discretized color legend (if that is what you want). However, I don’t think Vega-Lite (and hence Altair) supports this yet.”

Yes - I was trying to force a threshold scale type, since I saw it wasn’t an option in Vega-Lite. Can I make a feature request? 😃

“change the number of requested tick marks” & “if you want complete control over legend labels”

sweet!

This led me to an underlying Vega bug that I will fix soon!

Yay! Glad to hear it.

the version of vega-lite in colab is older than the current release

Alas!

0reactions
zanarmstrongcommented, Jul 5, 2018

Works like a charm - thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Encoding | Vega-Lite
By default, Vega-Lite automatically generates a scale and a legend for each field mapped to a mark property channel. If unspecified, properties ...
Read more >
vega grouping difference for vertical and horizontal bar chart?
I am trying to make a grouped bar chart with Vega. So I took the "stacked bar chart example" data (removed the stacking...
Read more >
Untitled
#Train Disintegration of ussr and india, A cold wall brand, Berocca energy tablets, Resumen compendio sinonimo, Romansas dviems akordai.
Read more >
Text Classification - Colaboratory - Google Colab
Collect a vocabulary of all tokens that appear in documents and number them. Encoding. Count how often each word appears in each document....
Read more >
Simple index - piwheels
... odoo-addon-disable-odoo-online first-pip-foo cookiecutter-leonardo-module example-pkg-ketanmb69 domain-discovery plover-word-tray pygame-spritesheet ...
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