pythonvega-litealtairvega

Using a list of colors for a bar chart in Altair


I am trying to provide a list of colors to bind to the bar marks in Altair, similar to how matplotlib's pyplot.bar(color=list_of_colors) can specify the color for each individual bar, like in the example here. Additionally, I am also using the edgecolor attribute in matplotlib. Is it possible to do both these things in Altair as well? If so, example code would be great.


Solution

  • You can use the list of colors to create a column that contains the raw value of the color you want to use and set .scale(None) as per this section of the docs..

    The equivalent to edgecolor is called stroke which you use the same way as color.