初学Bokeh:设置坐标轴外观【17】跬步

发布时间 2023-10-19 10:01:16作者: ohfaint

初学Bokeh:设置坐标轴外观【17】跬步

自定义坐标轴外观的选项包括:

  1. 为坐标轴设置标签;
  2. 为坐标轴显示的数字设计样式;
  3. 为坐标轴本身定义颜色和其他布局属性;

例如:

from bokeh.plotting import figure, show

# prepare some data
# 定义显示数据
x = [1, 2, 3, 4, 5]
y = [4, 5, 5, 7, 2]

# create a plot
# 创建绘图对象
p = figure(
    title="Customized axes example",    # 标题
    sizing_mode="stretch_width",    # 自适应宽度延展
    max_width=500,  # 最大宽度
    height=350, # 高度
)

# add a renderer
# 添加一个圆对象
p.circle(x, y, size=10)

# change some things about the x-axis
# 设置x轴属性
p.xaxis.axis_label = "Temp" # x轴的标签文本:Temp
p.xaxis.axis_line_width = 3 # x轴的线宽:3
p.xaxis.axis_line_color = "red" # x轴的颜色:红色

# change some things about the y-axis
# 设置y轴属性
p.yaxis.axis_label = "Pressure" # y轴标签文本
p.yaxis.major_label_text_color = "orange"   # y轴标签字体颜色
p.yaxis.major_label_orientation = "vertical"    # y轴标签显示方向

# change things on all axes
# PS:"minor_tick_in" 和 "minor_tick_out" 同时设置,那么 "minor_tick_out" 的设置优先级更高
# 设置绘图的次要刻度线(minor ticks)长度,次要刻度线表示主要刻度线之间的增量
p.axis.minor_tick_in = -3
# 设置图表的次要刻度线(minor ticks)向外延伸的距离
p.axis.minor_tick_out = 6

# show the results
show(p)

fig17-1