bqplot - 在情节外打勾
bqplot - Tick placement outside of plot
我正在尝试将 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)
结果:
我找到了一种方法,通过更改变量 ax_x 的两个内容来实现。
- 通过添加
tick_style={'font-size': 7}
来减小字体大小。
- 添加
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
我正在尝试将 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)
结果:
我找到了一种方法,通过更改变量 ax_x 的两个内容来实现。
- 通过添加
tick_style={'font-size': 7}
来减小字体大小。 - 添加
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