-
Notifications
You must be signed in to change notification settings - Fork 793
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
centred text marks on sorted heat map #1263
Comments
No, Altair 2.3 is still tied to Vega-Lite 2.6, as Vega-Lite 3 has yet to be released: >>> import altair as alt
>>> alt.VEGALITE_VERSION
'2.6.0' Regarding your question, I'm not sure how to answer it. When I run your code I get the following: |
Here is an example that is similar to what you want: starting from your code snippet, I removed the import altair as alt
import numpy as np
import pandas as pd
se=pd.DataFrame({'estimator': ['mean', 'mean', 'mean', 'mean',
'median', 'median', 'median', 'median',
'trim_mean', 'trim_mean', 'trim_mean', 'trim_mean'],
'distribution': ['normal', 'lognormal', 'one-wild', 'slash',
'normal', 'lognormal', 'one-wild', 'slash',
'normal', 'lognormal', 'one-wild', 'slash'],
'se': [.1, .4658, 1.90, np.nan,
.138, .1727, .1679, .7048,
.113, .177, .1433, .9649]})
c=alt.Chart().encode(
y=alt.Y('estimator'),
tooltip=['estimator', 'distribution', 'se']
)
a=c.mark_rect().encode(
x=alt.X('distribution', sort=['normal', 'lognormal', 'one-wild', 'slash'], axis=alt.Axis(labelAngle=0)),
color=alt.Color('se', scale=alt.Scale(domain=[0,.5]))
)
b=c.mark_text(align='center', baseline='middle').encode(
x=alt.X('distribution', sort=['normal', 'lognormal', 'one-wild', 'slash'],
axis=alt.Axis(title=None, labels=False, ticks=False)),
text='se',
)
alt.layer(a,b,data=se) |
Thanks Jake. Yes, I should have mentioned that my above example was made in the traditional notebook (so I can use RISE). Perhaps that is why it shows up oddly. In JL I get the same as you. Thanks again. |
It might be that you're using an older version of the vega extension in the notebook, in which case an older version of vega-lite is being used to render your chart. |
The rendering should be identical between notebook and jupyterlab if the vega extensions are up to date. |
Hmm, I have Vega-Lite 2.6.0 and Altair 2.3.0 in the notebook. Does that tell us that I have the vega extension up-to-date? |
The relevant package for the rendering of charts is not Altair, but the notebook vega extension. It's actually quite difficult to figure out what vega-lite version is being used by the notebook to render your charts (see vega/ipyvega#97 for the open issue on this subject... cc/ @domoritz: this is an example of a situation where that enhancement would be helpful to users). You need to update the vega package in order to use the most recent vega-lite version... version 1.4 is the most recent version. |
Thanks Jake. Will do. |
Hi Jake,
I assume that Altair 2.3 does not yet have the VL 3 sorting functionality mentioned here.
I am following a workaround involving making the x axis independent. This fixes the sorting but makes the text marks misaligned.
altair version 2.3
Is there a way to centre the text while maintaining the custom sort?
The text was updated successfully, but these errors were encountered: