{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Altair Debugging Guide\n", "\n", "In this notebook we show you common debugging techniques that you can use if you run into issues with Altair. \n", "\n", "You can jump to the following sections:\n", "\n", "* [Installation and Setup](#Installation) when Altair is not installed correctly\n", "* [Display Issues](#Display-Troubleshooting) when you don't see a chart\n", "* [Invalid Specifications](#Invalid-Specifications) when you get an error\n", "* [Properties are Being Ignored](#Properties-are-Being-Ignored) when you don't see any errors or warnings\n", "* [Asking for Help](#Asking-for-Help) when you get stuck\n", "* [Reporting Issues](#Reporting-Issues) when you find a bug\n", "\n", "In addition to this notebook, you might find the [Frequently Asked Questions](https://altair-viz.github.io/user_guide/faq.html) and [Display Troubleshooting](https://altair-viz.github.io/user_guide/troubleshooting.html) guides helpful. \n", "\n", "_This notebook is part of the [data visualization curriculum](https://github.com/uwdata/visualization-curriculum)._" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Installation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These instructions follow [the Altair documentation](https://altair-viz.github.io/getting_started/installation.html) but focus on some specifics for this series of notebooks. \n", "\n", "In every notebook, we will import the [Altair](https://github.com/altair-viz/altair) and [Vega Datasets](https://github.com/altair-viz/vega_datasets) packages. If you are running this notebook on [Colab](https://colab.research.google.com), Altair and Vega Datasets should be preinstalled and ready to go. The notebooks in this series are designed for Colab but should also work in Jupyter Lab or the Jupyter Notebook (the notebook requires a bit more setup [described below](#Special-Setup-for-the-Jupyter-Notebook)) but additional packages are required. \n", "\n", "If you are running in Jupyter Lab or Jupyter Notebooks, you have to install the necessary packages by running the following command in your terminal.\n", "\n", "```bash\n", "pip install altair vega_datasets\n", "```\n", "\n", "Or if you use [Conda](https://conda.io)\n", "\n", "```bash\n", "conda install -c conda-forge altair vega_datasets\n", "```\n", "\n", "You can run command line commands from a code cell by prefixing it with `!`. For example, to install Altair and Vega Datasets with [Pip](https://pip.pypa.io/), you can run the following cell." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: altair in /anaconda3/lib/python3.7/site-packages (4.0.1)\n", "Requirement already satisfied: vega_datasets in /anaconda3/lib/python3.7/site-packages (0.7.0)\n", "Requirement already satisfied: numpy in /anaconda3/lib/python3.7/site-packages (from altair) (1.15.4)\n", "Requirement already satisfied: jsonschema in /anaconda3/lib/python3.7/site-packages (from altair) (2.6.0)\n", "Requirement already satisfied: pandas in /anaconda3/lib/python3.7/site-packages (from altair) (0.23.4)\n", "Requirement already satisfied: toolz in /anaconda3/lib/python3.7/site-packages (from altair) (0.9.0)\n", "Requirement already satisfied: jinja2 in /anaconda3/lib/python3.7/site-packages (from altair) (2.10)\n", "Requirement already satisfied: entrypoints in /anaconda3/lib/python3.7/site-packages (from altair) (0.2.3)\n", "Requirement already satisfied: python-dateutil>=2.5.0 in /anaconda3/lib/python3.7/site-packages (from pandas->altair) (2.7.5)\n", "Requirement already satisfied: pytz>=2011k in /anaconda3/lib/python3.7/site-packages (from pandas->altair) (2018.7)\n", "Requirement already satisfied: MarkupSafe>=0.23 in /anaconda3/lib/python3.7/site-packages (from jinja2->altair) (1.1.0)\n", "Requirement already satisfied: six>=1.5 in /anaconda3/lib/python3.7/site-packages (from python-dateutil>=2.5.0->pandas->altair) (1.12.0)\n" ] } ], "source": [ "!pip install altair vega_datasets" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import altair as alt\n", "from vega_datasets import data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Make sure you are Using the Latest Version of Altair" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you are running into issues with Altair, first make sure that you are running the latest version. To check the version of Altair that you have installed, run the cell below. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'4.0.1'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To check what the latest version of altair is, go to [this page](https://pypi.org/project/altair/) or run the cell below (requires Python 3)." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4.0.1\n" ] } ], "source": [ "import urllib.request, json \n", "with urllib.request.urlopen(\"https://pypi.org/pypi/altair/json\") as url:\n", " print(json.loads(url.read().decode())['info']['version'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you are not running the latest version, you can update it with `pip`. You can update Altair and Vega Datasets by running this command in your terminal.\n", "\n", "```\n", "pip install -U altair vega_datasets\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Try Making a Chart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now you can create an Altair chart." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iris = data.iris()\n", "\n", "alt.Chart(iris).mark_point().encode(\n", " x='petalLength',\n", " y='petalWidth',\n", " color='species'\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Special Setup for the Jupyter Notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you are running in Jupyter Lab, Jupyter Notebook, or Colab (and have a working Internet connection) you should be seeing a chart. If you are running in another environment (or offline), you will need to tell Altair to use a different renderer;\n", "\n", "To activate a different renderer in a notebook cell:\n", "\n", "```python\n", "# to run in nteract, VSCode, or offline in JupyterLab\n", "alt.renderers.enable('mimebundle')\n", "\n", "```\n", "\n", "To run offline in Jupyter Notebook you must install an additional dependency, the `vega` package. Run this command in your terminal:\n", "\n", "```bash\n", "pip install vega\n", "```\n", "\n", "Then activate the notebook renderer:\n", "\n", "```python\n", "# to run offline in Jupyter Notebook\n", "alt.renderers.enable('notebook')\n", "\n", "```\n", "\n", "\n", "These instruction follow [the instructions on the Altair website](https://altair-viz.github.io/getting_started/installation.html#installation-notebook)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Display Troubleshooting\n", "\n", "If you are having issues with seeing a chart, make sure your setup is correct by following the [debugging instruction above](#installation). If you are still having issues, follow the [instruction about debugging display issues in the Altair documentation](https://altair-viz.github.io/user_guide/troubleshooting.html)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Non Existent Fields\n", "\n", "A common error is [accidentally using a field that does not exit](https://altair-viz.github.io/user_guide/troubleshooting.html#plot-displays-but-the-content-is-empty). " ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "df = pd.DataFrame({'x': [1, 2, 3],\n", " 'y': [3, 1, 4]})\n", "\n", "alt.Chart(df).mark_point().encode(\n", " x='x:Q',\n", " y='y:Q',\n", " color='color:Q' # <-- this field does not exist in the data!\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check the spelling of your files and print the data source to confirm that the data and fields exist. For instance, here you see that `color` is not a vaid field. " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
xy
013
121
234
\n", "
" ], "text/plain": [ " x y\n", "0 1 3\n", "1 2 1\n", "2 3 4" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Invalid Specifications\n", "\n", "Another common issue is creating an invalid specification and getting an error." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Invalid Properties\n", "\n", "Altair might show an `SchemaValidationError` or `ValueError`. Read the error message carefully. Usually it will tell you what is going wrong. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For example, if you forget the mark type, you will see this `SchemaValidationError`. " ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "ename": "SchemaValidationError", "evalue": "Invalid specification\n\n altair.vegalite.v4.api.Chart, validating 'required'\n\n 'mark' is a required property\n ", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mSchemaValidationError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m/anaconda3/lib/python3.7/site-packages/altair/vegalite/v4/api.py\u001b[0m in \u001b[0;36mto_dict\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 372\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdct\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 373\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'validate'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'deep'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 374\u001b[0;31m \u001b[0mdct\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mTopLevelMixin\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 375\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 376\u001b[0m \u001b[0;31m# TODO: following entries are added after validation. Should they be validated?\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/anaconda3/lib/python3.7/site-packages/altair/utils/schemapi.py\u001b[0m in \u001b[0;36mto_dict\u001b[0;34m(self, validate, ignore, context)\u001b[0m\n\u001b[1;32m 305\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 306\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mjsonschema\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mValidationError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 307\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mSchemaValidationError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 308\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 309\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mSchemaValidationError\u001b[0m: Invalid specification\n\n altair.vegalite.v4.api.Chart, validating 'required'\n\n 'mark' is a required property\n " ] }, { "data": { "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.Chart(data.cars()).encode(\n", " y='Horsepower'\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or if you use a non-existent channel, you get a `ValueError`. " ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/anaconda3/lib/python3.7/site-packages/altair/utils/core.py:548: UserWarning: Unrecognized encoding channel 'z'\n", " warnings.warn(\"Unrecognized encoding channel '{}'\".format(encoding))\n" ] }, { "ename": "SchemaValidationError", "evalue": "Invalid specification\n\n altair.vegalite.v4.schema.core.FacetedEncoding, validating 'additionalProperties'\n\n Additional properties are not allowed ('z' was unexpected)\n ", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mSchemaValidationError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m/anaconda3/lib/python3.7/site-packages/altair/vegalite/v4/api.py\u001b[0m in \u001b[0;36mto_dict\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 372\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdct\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 373\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'validate'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'deep'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 374\u001b[0;31m \u001b[0mdct\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mTopLevelMixin\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 375\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 376\u001b[0m \u001b[0;31m# TODO: following entries are added after validation. Should they be validated?\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/anaconda3/lib/python3.7/site-packages/altair/utils/schemapi.py\u001b[0m in \u001b[0;36mto_dict\u001b[0;34m(self, validate, ignore, context)\u001b[0m\n\u001b[1;32m 297\u001b[0m result = _todict({k: v for k, v in self._kwds.items()\n\u001b[1;32m 298\u001b[0m if k not in ignore},\n\u001b[0;32m--> 299\u001b[0;31m validate=sub_validate, context=context)\n\u001b[0m\u001b[1;32m 300\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 301\u001b[0m raise ValueError(\"{} instance has both a value and properties : \"\n", "\u001b[0;32m/anaconda3/lib/python3.7/site-packages/altair/utils/schemapi.py\u001b[0m in \u001b[0;36m_todict\u001b[0;34m(obj, validate, context)\u001b[0m\n\u001b[1;32m 58\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0m_todict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalidate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mobj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 59\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 60\u001b[0;31m return {k: _todict(v, validate, context) for k, v in obj.items()\n\u001b[0m\u001b[1;32m 61\u001b[0m if v is not Undefined}\n\u001b[1;32m 62\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'to_dict'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/anaconda3/lib/python3.7/site-packages/altair/utils/schemapi.py\u001b[0m in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 59\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 60\u001b[0m return {k: _todict(v, validate, context) for k, v in obj.items()\n\u001b[0;32m---> 61\u001b[0;31m if v is not Undefined}\n\u001b[0m\u001b[1;32m 62\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'to_dict'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 63\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mobj\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/anaconda3/lib/python3.7/site-packages/altair/utils/schemapi.py\u001b[0m in \u001b[0;36m_todict\u001b[0;34m(obj, validate, context)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[0;34m\"\"\"Convert an object to a dict representation.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSchemaBase\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 56\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobj\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcontext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 57\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtuple\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 58\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0m_todict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalidate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mobj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/anaconda3/lib/python3.7/site-packages/altair/utils/schemapi.py\u001b[0m in \u001b[0;36mto_dict\u001b[0;34m(self, validate, ignore, context)\u001b[0m\n\u001b[1;32m 305\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 306\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mjsonschema\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mValidationError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 307\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mSchemaValidationError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 308\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 309\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mSchemaValidationError\u001b[0m: Invalid specification\n\n altair.vegalite.v4.schema.core.FacetedEncoding, validating 'additionalProperties'\n\n Additional properties are not allowed ('z' was unexpected)\n " ] }, { "data": { "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.Chart(data.cars()).mark_point().encode(\n", " z='Horsepower'\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Properties are Being Ignored\n", "\n", "Altair might ignore a property that you specified. In the chart below, we are using a `text` channel, which is only compatible with `mark_text`. You do not see an error or a warning about this in the notebook. However, the underlying Vega-Lite library will show a warning in the browser console. Press Alt+Cmd+I on Mac or Alt+Ctrl+I on Windows and Linux to open the developer tools and click on the `Console` tab. When you run the example in the cell below, you will see a the following warning.\n", "\n", "```\n", "WARN text dropped as it is incompatible with \"bar\".\n", "```" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.Chart(data.cars()).mark_bar().encode(\n", " y='mean(Horsepower)',\n", " text='mean(Acceleration)'\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you find yourself debugging issues related to Vega-Lite, you can open the chart in the [Vega Editor](https://vega.github.io/editor/) either by clicking on the \"Open in Vega Editor\" link at the bottom of the chart or in the action menu (click to open) at the top right of a chart. The Vega Editor provides additional debugging but you will be writing Vega-Lite JSON instead of Altair in Python.\n", "\n", "**Note**: The Vega Editor may be using a newer version of Vega-Lite and so the behavior may vary." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Asking for Help\n", "\n", "If you find a problem with Altair and get stuck, you can ask a question on Stack Overflow. Ask your question with the `altair` and `vega-lite` tags. You can find a list of questions people have asked before [here](https://stackoverflow.com/questions/tagged/altair). " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reporting Issues\n", "\n", "If you find a problem with Altair and believe it is a bug, please [create an issue in the Altair GitHub repo](https://github.com/altair-viz/altair/issues/new) with a description of your problem. If you believe the issue is related to the underlying Vega-Lite library, please [create an issue in the Vega-Lite GitHub repo](https://github.com/vega/vega-lite/issues/new)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.1" } }, "nbformat": 4, "nbformat_minor": 4 }