英文:
altair heatmap: how to apply axis labels wrap, without losing meaning in values and cell values?
问题
在坐标轴上有一些很长的标签(见下面的示例)。此处 在vega编辑器中。
如果我应用wrap
df['l_x'] = df['l_x'].apply(wrap, args=[10])
df['l_y'] = df['l_y'].apply(wrap, args=[10])
它适用于标签,但是我的图表中的颜色失去了意义(查看新的1️⃣白色单元格和2️⃣单元格的新颜色),而单元格标签消失了,可能是因为输出列表破坏了一切。此处 在vega编辑器中。
如何避免这种情况?
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.
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?
答案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.
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论