[英]How to increse label spacing and tick spacing in case of multiple y-axis in altair?
我正在嘗試增加繪圖的易讀性,因為 y 軸標簽(左側)已經重疊並調整它們之間的刻度范圍和間隔。請幫助我這樣做多軸組合圖
import altair as alt
from vega_datasets import data
source = data.seattle_weather()
base = alt.Chart(source).encode( alt.X('month(date):T', axis=alt.Axis(title=None)))
area = base.mark_area(opacity=0.3, color='#57A44C').encode(
alt.Y('average(temp_max)',
axis=alt.Axis(title='Avg. Temperature (°C)', titleColor='#57A44C')),
alt.Y2('average(temp_min)'))
line = base.mark_line(stroke='#5276A7', interpolate='monotone').encode(
alt.Y('average(precipitation)',
axis=alt.Axis(title='Precipitation (inches)', titleColor='#5276A7')))
line2 = base.mark_line(stroke='#5276A7', interpolate='monotone').encode(
alt.Y('average(wind)',
axis=alt.Axis(title='wind', titleColor='#5276A7')))
alt.layer(area, line,line2).resolve_scale(y = 'independent').configure_axisY()
在技術上可以使用offset
參數移動第三個 y 軸:
import altair as alt
from vega_datasets import data
source = data.seattle_weather()
base = alt.Chart(source).encode( alt.X('month(date):T', axis=alt.Axis(title=None)))
area = base.mark_area(opacity=0.3, color='#57A44C').encode(
alt.Y('average(temp_max)',
axis=alt.Axis(title='Avg. Temperature (°C)', titleColor='#57A44C')),
alt.Y2('average(temp_min)'))
line = base.mark_line(stroke='#5276A7', interpolate='monotone').encode(
alt.Y('average(precipitation)',
axis=alt.Axis(title='Precipitation (inches)', titleColor='#5276A7')))
line2 = base.mark_line(stroke='coral', interpolate='monotone').encode(
alt.Y('average(wind)',
axis=alt.Axis(title='wind', titleColor='coral', offset=60)))
alt.layer(area, line,line2).resolve_scale(y = 'independent').configure_axisY()
但是,我會考慮制作單獨的圖,因為閱讀具有多個 y 軸的圖表可能會變得困難。 如果垂直堆疊圖,仍然很容易比較三種不同測量值的趨勢:
base = alt.Chart(source, height=150).encode(alt.X('month(date):T', axis=None))
area = base.mark_area(opacity=0.3, color='#57A44C').encode(
alt.Y('average(temp_max)',
axis=alt.Axis(title='Avg. Temperature (°C)', titleColor='#57A44C')),
alt.Y2('average(temp_min)'))
line = base.mark_line(stroke='#5276A7', interpolate='monotone').encode(
alt.Y('average(precipitation)',
axis=alt.Axis(title='Precipitation (inches)', titleColor='#5276A7')))
line2 = base.mark_line(stroke='coral', interpolate='monotone').encode(
alt.Y('average(wind)',
axis=alt.Axis(title='wind', titleColor='coral')),
alt.X('month(date):T')
)
alt.vconcat(area, line, line2, spacing=0).resolve_scale(x='shared')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.