【问题标题】:bqplot - Tick placement outside of plotbqplot - 在绘图之外放置刻度
【发布时间】:2020-01-30 14:50:42
【问题描述】:

我正在尝试将 x 轴刻度线放置在绘图之外,而不是从 x 轴开始,如下所示。您对如何实现这一点有任何提示吗?

我的绘图位代码:

x_data = df_ts.columns.values.tolist()
y_end = df_ts.loc[end_date, :].values.flatten()
y_start = df_ts.loc[start_date, :].values.flatten()

x_sc = OrdinalScale()
y_sc = LinearScale()
ax_x = Axis(label='RIC', scale=x_sc, grid_lines='solid', tick_rotate=90)
ax_y = Axis(label='%', scale=y_sc, orientation='vertical',tick_format='0.2f')

line = Lines(x=x_data, y=[y_end, y_start], scales={'x': x_sc, 'y': y_sc}, 
             display_legend=True, labels=[end_date, start_date], stroke_width=1)
bar = Bars(x=x_data, y=df_diff.tolist(), scales={'x': x_sc, 'y': y_sc}, padding=0.5)

fig = Figure(marks=[line, bar], axes=[ax_x, ax_y], title='Swap rates and differences', legend_location='top-left')
display(fig)

结果:

【问题讨论】:

    标签: python bqplot


    【解决方案1】:

    我找到了一种方法,方法是为变量 ax_x 更改两件事。

    1. 通过添加tick_style={'font-size': 7}来减小字体大小。
    2. 添加offset={'scale':x_sc, 'value':10}

    新代码如下:

    x_data = df_ts.columns.values.tolist()
    y_end = df_ts.loc[end_date, :].values.flatten()
    y_start = df_ts.loc[start_date, :].values.flatten()
    
    x_sc = OrdinalScale()
    y_sc = LinearScale()
    ax_x = Axis(label='RIC', scale=x_sc, grid_lines='solid', tick_rotate=90, tick_style={'font-size': 7}, label_offset='40',
               offset={'scale':x_sc, 'value':10})
    ax_y = Axis(label='%', scale=y_sc, orientation='vertical',tick_format='0.2f', label_offset='-40')
    
    line = Lines(x=x_data, y=[y_end, y_start], scales={'x': x_sc, 'y': y_sc}, 
                 display_legend=True, labels=[end_date, start_date], stroke_width=1)
    bar = Bars(x=x_data, y=df_diff.tolist(), scales={'x': x_sc, 'y': y_sc}, padding=0.5)
    
    fig = Figure(marks=[line, bar], axes=[ax_x, ax_y], title='Swap rates and differences', legend_location='top-left')
    display(fig)
    

    它显示为: Results

    【讨论】:

      猜你喜欢
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-11
      • 2017-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多