altair
altair copied to clipboard
`.title()` does not support all the argument in `axis(title=...)` but still lists them in the docstring
Dear all,
I tried the example from https://altair-viz.github.io/gallery/layered_chart_with_dual_axis.html, both the Method syntax as well as the Attribute syntax.
On my setup (jupyterlab 4 + altair 5.0.1) only the attribute syntax colours the axis labels with the colours from the graph. The Method syntax colors the axis labels black.
I am happily using the Attribute syntax now. Is this a bug? Of the documentation? Of the library itself?
Thanks in advance, Franz
Please follow these steps to make it more efficient to solve your issue:
- [ x] Since Altair is a Python wrapper around the Vega-Lite visualization grammar, most bugs should be reported directly to Vega-Lite. You can click the Action Button of your Altair chart and "Open in Vega Editor" to create a reproducible Vega-Lite example and see if you get the same error in the Vega Editor.
- [ x] Search for duplicate issues.
- [x ] Use the latest version of Altair.
- [ x] Describe how to reproduce the bug and include the full code and data to reproduce it, ideally using a sample data set from
vega_datasets.
Thanks for reporting, the reason is that Vega-Lite's title parameter only takes a string, so the title() method (or title= parameter in version <=4) can only take a string of the title text and no parameters for customizing the title (so other parameters such as subtitle= also does not work inside title(). This is currently not clear from the docstring which mentions that it it possible to pass parameters to title, so we should either change the docstring or silently pass those parameters forward to axis(title={}).
Shorter examples:
import altair as alt
from vega_datasets import data
source = data.seattle_weather()
alt.Chart(source).mark_point().encode(
alt.X('date').title('This should be red', color='red')
)
alt.Chart(source).mark_point().encode(
alt.X('date').axis(title='This should be red', titleColor='red')
)
Ok, thanks this makes sense now...
I just checked, it is still an issue with 5.2.0.
Yes, this issue will be closed once a PR has been submitted to fix it. Feel free to create one if you have the time to get familiar with the code base.