Altair热力图:如何应用轴标签换行,而不丧失数值和单元格值的含义?

huangapple go评论55阅读模式
英文:

altair heatmap: how to apply axis labels wrap, without losing meaning in values and cell values?

问题

在坐标轴上有一些很长的标签(见下面的示例)。此处 在vega编辑器中。

Altair热力图:如何应用轴标签换行,而不丧失数值和单元格值的含义?

如果我应用wrap

df['l_x'] = df['l_x'].apply(wrap, args=[10])
df['l_y'] = df['l_y'].apply(wrap, args=[10])

它适用于标签,但是我的图表中的颜色失去了意义(查看新的1️⃣白色单元格和2️⃣单元格的新颜色),而单元格标签消失了,可能是因为输出列表破坏了一切。此处 在vega编辑器中。
如何避免这种情况?

Altair热力图:如何应用轴标签换行,而不丧失数值和单元格值的含义?

3: https://vega.github.io/editor/#/url/vega-lite/N4Igxg9gdgZglgcxALlANzgUwO4tJKAFzigFcJSBnAdTgBNCALFAZgAY2AacaYsiygAlMiRoVYcAvpO50AhoTl4QUOQFtMKEPMUBaMGAAshuQEYwAJjYWAnCcMA2FgFYARqdNsb71wA5nzgDsmE4gMiBqcgBOANZaUZhg4tyYUJB0JEioPAA2EFHK8Jg5dFpoINw5mAippdnEhFVaYdyUYHJN2VFyUDUoANogAMQwgTCuMDAVw2y+7A6uIAC64YQAngAOmsggAI6kPQ0KcGia4QAehVglWjkA+pet+eLZRTc7UNMQG1pqJF9ROiYAo7ORtWqZFogBqdEAABQSGSSmDoAAIcnJXMVpustlooBA-qoclC1ldinUQPcyU8oi9QG9KZ9uN9fv8WYDgVowWAIb0oTDtiAACpRUiYdGY7HcXFCglEjphcKMEQIMSsBxcEDYehMDVagAkbRVkS0YkIG0oyAA9NbTgg5AA6BBwJikVyOuAQa3GzCRO3VOS6HKuzB25yOiyOtiOgBWlGg0x0YMwhEoymT+iMJnMVls9icbg8Xh8-iCIRYA1An2Qpm4l2QWrJje45WQLBYNkCDmclQeAxUEFRyeWfebgwJw4UShWnGrKAs9ZQTZQphYhlbq6sgV7VP7yAnQ5HSzHA4AYvlMJRCNxZIl6OQqLeQK4ohA5GiqnIprP5+2ly2IDNmu dibsggRrhue4NoeU6KKOe7jiAF4JNez6kFAMQEtgny-ioKBQQ2kHc

英文:

I have some long label in axis (see the example below). Here in the vega editor.

Altair热力图:如何应用轴标签换行,而不丧失数值和单元格值的含义?

If I apply wrap

df['l_x'] = df['l_x'].apply(wrap, args=[10])
df['l_y'] = df['l_y'].apply(wrap, args=[10])

it works for the labels, but the colors in my graph lose meaning (look at the new 1️⃣ white cells and 2️⃣ generally to the new colors of cells) and the cell labels disappear, probably because the output lists break everything. Here in the vega editor.
How to avoid this?

Altair热力图:如何应用轴标签换行,而不丧失数值和单元格值的含义?

答案1

得分: 0

I have first applied python wrap and then a search and replace in my fields

wrap=10
df['l_x'] = df['l_x'].str.wrap(wrap)
df['l_y'] = df['l_y'].str.wrap(wrap)
df['l_x'] = df['l_x'].str.replace('\n', '@')
df['l_y'] = df['l_y'].str replace('\n', '@')

Then I have set for x and y

axis=alt.Axis(labelExpr="split(datum.Label, '@')")

And now it works. Thank you Casey Haber.

Altair热力图:如何应用轴标签换行,而不丧失数值和单元格值的含义?

英文:

I have first applied python wrap and then a search and replace in my fields

wrap=10
df['l_x'] = df['l_x'].str.wrap(wrap)
df['l_y'] = df['l_y'].str.wrap(wrap)
df['l_x'] = df['l_x'].str.replace('\n', '@')
df['l_y'] = df['l_y'].str.replace('\n', '@')

Then I have set for x and y

axis=alt.Axis(labelExpr="split(datum.Label,'@')")

And now it works. Thank you Casey Haber.

Altair热力图:如何应用轴标签换行,而不丧失数值和单元格值的含义?

huangapple
  • 本文由 发表于 2023年4月10日 21:57:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977755.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定