|
1293 | 1293 | "source": [
|
1294 | 1294 | "import geopandas as gpd\n",
|
1295 | 1295 | "\n",
|
1296 |
| - "from bokeh.models import ColorBar, GeoJSONDataSource\n", |
| 1296 | + "from bokeh.models import GeoJSONDataSource\n", |
1297 | 1297 | "from bokeh.palettes import Cividis\n",
|
1298 | 1298 | "from bokeh.transform import linear_cmap"
|
1299 | 1299 | ]
|
|
1422 | 1422 | "cell_type": "markdown",
|
1423 | 1423 | "metadata": {},
|
1424 | 1424 | "source": [
|
1425 |
| - "- Set up and add the **[ColorBar](05_styling.ipynb#Color-mappers-and-pallets)**.\n", |
1426 |
| - " The ColorBar provides a key to which color relates to which\n", |
| 1425 | + "- Set up and add the **[color bar](05_styling.ipynb#Color-mappers-and-pallets)**.\n", |
| 1426 | + " The color bar provides a key to which color relates to which\n", |
1427 | 1427 | " number of routes. Adding the color bar takes two steps:\n",
|
1428 |
| - " 1. Defining the color bar as a ``ColorBar`` object. This uses the following\n", |
1429 |
| - " parameters:\n", |
1430 |
| - " - `color_mapper`: The color mapper to use. In this case, you use the\n", |
1431 |
| - " linear color mapper that you defined for the patches renderer in the\n", |
1432 |
| - " previous step.\n", |
| 1428 | + " 1. Defining the color bar with the ``construct_color_bar()`` method. This uses the\n", |
| 1429 | + " following parameters:\n", |
1433 | 1430 | " - `formatter`: How to format the numbers in the color bar. Use a\n",
|
1434 | 1431 | " `NumeralTickFormatter` with the format string `0,0`. This means that\n",
|
1435 | 1432 | " Bokeh uses a comma as a thousands separator.\n",
|
1436 |
| - " - `orientation`: The orientation of the color bar. In this case, create a\n", |
1437 |
| - " horizontal color bar by setting the value to `\"horizontal\"`.\n", |
1438 | 1433 | " - `height`: The height of the color bar in pixels.\n",
|
1439 |
| - " 2. Adding the `ColorBar` object to the figure. Use the `add_layout` method to\n", |
| 1434 | + " 2. Adding the color bar to the figure. Use the `add_layout` method to\n", |
1440 | 1435 | " add the object and place it below the map plot."
|
1441 | 1436 | ]
|
1442 | 1437 | },
|
|
1447 | 1442 | "outputs": [],
|
1448 | 1443 | "source": [
|
1449 | 1444 | "# add the color bar\n",
|
1450 |
| - "color_bar = ColorBar(color_mapper=us.glyph.fill_color.transform, formatter=NumeralTickFormatter(format=\"0,0\"), orientation=\"horizontal\", height=10)\n", |
| 1445 | + "color_bar = us.construct_color_bar(formatter=NumeralTickFormatter(format=\"0,0\"), height=10)\n", |
| 1446 | + "\n", |
1451 | 1447 | "map_plot.add_layout(obj=color_bar, place=\"below\")"
|
1452 | 1448 | ]
|
1453 | 1449 | },
|
|
1482 | 1478 | "source": [
|
1483 | 1479 | "import geopandas as gpd\n",
|
1484 | 1480 | "\n",
|
1485 |
| - "from bokeh.models import ColorBar, GeoJSONDataSource\n", |
| 1481 | + "from bokeh.models import GeoJSONDataSource\n", |
1486 | 1482 | "from bokeh.palettes import Cividis\n",
|
1487 | 1483 | "from bokeh.transform import linear_cmap\n",
|
1488 | 1484 | "\n",
|
|
1523 | 1519 | ")\n",
|
1524 | 1520 | "\n",
|
1525 | 1521 | "# add color bar\n",
|
1526 |
| - "color_bar = ColorBar(color_mapper=us.glyph.fill_color.transform, formatter=NumeralTickFormatter(format=\"0,0\"), orientation=\"horizontal\", height=10)\n", |
| 1522 | + "color_bar = us.construct_color_bar(formatter=NumeralTickFormatter(format=\"0,0\"), height=10)\n", |
1527 | 1523 | "map_plot.add_layout(obj=color_bar, place=\"below\")\n",
|
1528 | 1524 | "\n",
|
1529 | 1525 | "show(map_plot)"
|
|
1928 | 1924 | "nbconvert_exporter": "python",
|
1929 | 1925 | "pygments_lexer": "ipython3",
|
1930 | 1926 | "version": "3.11.4"
|
1931 |
| - }, |
1932 |
| - "vscode": { |
1933 |
| - "interpreter": { |
1934 |
| - "hash": "0494a81e5f69860dcb844ce8e12eb9c88a7e813ddbfb0fbade72137f5ce45437" |
1935 |
| - } |
1936 | 1927 | }
|
1937 | 1928 | },
|
1938 | 1929 | "nbformat": 4,
|
|
0 commit comments