[英]Choosing how many x axis labels display on an altair chart in python
I have an altair chart where I am using mark_rectangle.我有一个使用 mark_rectangle 的 altair 图表。 I want to choose how many x axis labels are displayed to have the marks form squares in the visualization.
我想选择显示多少 x 轴标签以使标记在可视化中形成正方形。 Or perhaps I want to choose the range of the x axis labels.
或者我想选择 x 轴标签的范围。 Right now there are far too many labels being displayed.
现在显示的标签太多了。 Below I have an example of what I am trying to achieve and what my current output chart is.
下面我有一个我想要实现的示例以及我当前的 output 图表是什么。 I apologize if the issue is due to something else, I am currently figuring out altair.
如果问题是由其他原因引起的,我深表歉意,我目前正在找出 altair。
My code currently:我的代码目前:
alt.Chart(temdf).mark_rect().encode(
x=alt.X('norm:O', title='', axis=alt.Axis(grid=False, labelAngle=360)),
y=alt.Y('term:N', title='', axis=alt.Axis(grid=False)),
color=alt.Color('norm:O', title='', scale=alt.Scale(scheme='blues'), legend=None),
facet=alt.Facet('title:N', title='',columns=3, header=alt.Header(labelOrient='bottom', labelPadding=15, labelAngle=360),
sort=alt.EncodingSortField(field = 'title', order='ascending'))
What I am trying to achieve:我想要达到的目标:
My current output:我目前的 output:
You have declared that your x data is type O
, meaning ordinal , ie ordered categories.您已声明您的 x 数据是类型
O
,意思是ordinal ,即有序类别。 This says that you want one distinct x bin for each unique value in your dataset.这表示您希望数据集中的每个唯一值都有一个不同的 x bin。 If you want fewer ordinal x bins, you should use a dataset with fewer unique values.
如果您想要更少的序数 x 箱,您应该使用具有更少唯一值的数据集。
Alternatively, if you don't want each unique x value to have its own label, you can use the quantitative data type (ie x=alt.X('norm:Q')
), or perhaps bin your data x=alt.X('norm:O', bin=True)
.或者,如果您不希望每个唯一的 x 值都有自己的 label,则可以使用定量数据类型(即
x=alt.X('norm:Q')
),或者可能将数据x=alt.X('norm:O', bin=True)
。 Be sure to bin your color encoding as well if you use the latter.如果您使用后者,请务必合并您的颜色编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.