Altair: Hiding the legend for a channel

Created on 17 Nov 2016  路  10Comments  路  Source: altair-viz/altair

In vega-lite JSON, under encoding I was able to do the following:

"opacity": {
  "field": "positives",
  "type": "quantitative",
  "legend": false
}

The "legend": false line suppressed the rendering of the opacity legend.

In altair, I tried specifying the following argument for .encode():

opacity = altair.Opacity('positives', legend=False)

This raised the error:

TraitError: The 'legend' trait of an Opacity instance must be a Legend or None, but a value of class 'bool' (i.e. False) was specified.

Any way to hide the legend for a channel in altair?

vega-lite-related

Most helpful comment

In Altair 2.0, this can be done with legend=None.

All 10 comments

As you may notice from my previous issue (https://github.com/altair-viz/altair/issues/264), most of my plotting customizations consist of getting rid of things and minimizing how much space the figure consumes :smile_cat:

The ability to do legend=False was added in a recent version of Vega-Lite. As of Vega-Lite 1.2.1 the schema does not support legend=False. Allowing that would require updating Altair to work with Vega-Lite version 1.3.

Ah yes, I see the vega-lite v1.3.0 release notes mention:

Make setting axis or legend = null as the default way to disable them.

For now, I'll try finishing my visualization by editing the vega-lite JSON, which in the long term should help me with contributing to altair!

Note: In current http://vega.github.io/vega-editor/, setting "legend": false in vega-lite hides legend, but "legend": null does not. CC @arvind

@dhimmel Looks like we forgot to update vega-editor to 1.3. (It's still 1.2 there.)

@domoritz will update that together with the new 1.x update soon.

Also note that the next version of vega editor will explicitly list version in the UI.

@kanitw is this be fixed in vega-lite latest 1.x?

Looks like in 1.3.1 the only options are an object or null (https://github.com/vega/schema/blob/master/vega-lite/v1.3.1.json#L988). You can pass false but we don't want to add it to the schema.

Looks like in 1.3.1 the only options are an object or null

@domoritz does null remove the legend entirely?

It should! If not, that's a bug.

Altair doesn't yet support explicit nulls, so now that they have meaning in Vega-Lite we will need to add that. I'd probably opt to introduce an altair.null object for cases like this when the user wants to be explicit (currently None tells Altair to leave that entry out of the schema, and there's no easy way to change that behavior).

In Altair 2.0, this can be done with legend=None.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fischcheng picture fischcheng  路  4Comments

maxgerma picture maxgerma  路  3Comments

mroswell picture mroswell  路  4Comments

firasm picture firasm  路  3Comments

floringogianu picture floringogianu  路  3Comments