我有以下的数据框,想使用Python的
剧本中的情节如下所示:
altair
库来绘制条形图。但是,我不知道如何扩大每个条的宽度(与在matplotlib
中使用width=0.5
参数相同)。import pandas as pd
from altair import *
ls = [[ 1, 734], [ 2, 1705], [ 3, 2309],
[ 4, 2404], [ 5, 2022], [ 6, 1538],
[ 7, 1095], [ 8, 770], [ 9, 485],
[ 10, 312], [ 11, 237], [ 12, 153],
[ 13, 103], [ 14, 69], [ 15, 47],
[ 16, 39], [ 17, 43], [ 18, 28],
[ 19, 18]]
df = pd.DataFrame(ls, columns=['n_authors', 'n_posters'])
这是使用altair
的绘图函数。
bar_chart = Chart(df).mark_bar().encode(
x=X('n_authors', title='Number of Authors in a Poster'),
y=Y('n_posters', title='Number of Posters'),
).configure_facet_cell(
strokeWidth=1.0,
height=200,
width=300
)
bar_chart.display()
剧本中的情节如下所示:
![Imgur](https://i.imgur.com/7IWuFMY.png)
Chart(df).mark_bar(size=20).encode(x='X', y='Y').properties(width=800)
。 - getup8