Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

escape special characters in names... #2494

Closed
franzhaas opened this issue Sep 14, 2021 · 1 comment
Closed

escape special characters in names... #2494

franzhaas opened this issue Sep 14, 2021 · 1 comment
Labels

Comments

@franzhaas
Copy link
Contributor

franzhaas commented Sep 14, 2021

Dear all,

using altair 4.1.0.

I tried to use altair to plot data annotating the data with the dimension. For example volts written as [V]. If i remove the closing ], I even get a javascript error.

Is there a way to use strings with special characters as names with altair? Is thsi related to #1326? Altogh for me a single bacslash did not solve my issue, the javascript error goes away but there is no data plotted...

thanks,
Franz

---8<---8<---8<---8<---8<---8<---8<---8<---

import altair as alt
import numpy as np
import pandas as pd

x = np.arange(100)

xname = "x [mV"

source = pd.DataFrame({xname: x, 'f(x)': np.sin(x / 5)})

alt.Chart(source).mark_line().encode(
    x=alt.X(field=xname, type="quantitative"),
    y='f(x)'
)
@franzhaas franzhaas added the bug label Sep 14, 2021
@jakevdp
Copy link
Collaborator

jakevdp commented Sep 14, 2021

Thanks for the question! There is some documentation around escaping special characters in the field attribute here: https://altair-viz.github.io/user_guide/encoding.html#encoding-channel-options

For your example, you can make it work like this:

import altair as alt
import numpy as np
import pandas as pd

x = np.arange(100)

xname = "x [mV"
xname_escaped = "x \\[mV"

source = pd.DataFrame({xname: x, 'f(x)': np.sin(x / 5)})

alt.Chart(source).mark_line().encode(
    x=alt.X(field=xname_escaped, type="quantitative"),
    y='f(x)'
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants