|
13 | 13 | "```" |
14 | 14 | ] |
15 | 15 | }, |
| 16 | + { |
| 17 | + "cell_type": "markdown", |
| 18 | + "metadata": {}, |
| 19 | + "source": [ |
| 20 | + "(option-attr_labels)=\n", |
| 21 | + "## `attr_labels`\n", |
| 22 | + "\n", |
| 23 | + "The `attr_labels` option controls whether hvPlot automatically uses xarray object attributes as labels for dimensions in your plots. This feature helps create more descriptive plots by extracting meaningful labels and units from your xarray data's metadata.\n", |
| 24 | + "\n", |
| 25 | + "When set to `True`, hvPlot will look for `long_name` attributes to use as dimension labels and `units` attributes to add unit information. If set to `None` (the default), hvPlot attempts to extract labels without showing warnings if attributes aren't found. Setting it to `False` disables this automatic labeling behavior entirely.\n", |
| 26 | + "\n", |
| 27 | + ":::{note}\n", |
| 28 | + "This option only applies to xarray data objects that contain attributes. It has no effect on pandas DataFrames or other data types.\n", |
| 29 | + ":::" |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "code", |
| 34 | + "execution_count": null, |
| 35 | + "metadata": {}, |
| 36 | + "outputs": [], |
| 37 | + "source": [ |
| 38 | + "import hvplot.xarray # noqa\n", |
| 39 | + "\n", |
| 40 | + "ds = hvplot.sampledata.air_temperature(\"xarray\").sel(time='2014-02-25 12:00')\n", |
| 41 | + "print(\"Longitude coordinates:\", ds.coords['lon'].attrs)\n", |
| 42 | + "print(\"Latitude coordinates:\", ds.coords['lat'].attrs)" |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "cell_type": "code", |
| 47 | + "execution_count": null, |
| 48 | + "metadata": {}, |
| 49 | + "outputs": [], |
| 50 | + "source": [ |
| 51 | + "plot1 = ds.hvplot.image(\n", |
| 52 | + " title=\"attr_labels=None (default)\",\n", |
| 53 | + " width=350, height=250,\n", |
| 54 | + ")\n", |
| 55 | + "\n", |
| 56 | + "plot2 = ds.hvplot.image(\n", |
| 57 | + " attr_labels=False,\n", |
| 58 | + " title=\"attr_labels=False\",\n", |
| 59 | + " width=350, height=250\n", |
| 60 | + ")\n", |
| 61 | + "\n", |
| 62 | + "plot1 + plot2" |
| 63 | + ] |
| 64 | + }, |
16 | 65 | { |
17 | 66 | "cell_type": "markdown", |
18 | 67 | "metadata": {}, |
|
0 commit comments