📜  散景 - 自定义图例

📅  最后修改于: 2022-05-13 01:54:49.210000             🧑  作者: Mango

散景 - 自定义图例

图表的图例反映了图表 Y 轴中显示的数据。在散景中,图例对应于字形。这篇文章如何自定义出现在散景图中的传奇。

我们可以使用它的几个属性来自定义图例,例如位置、颜色、线颜色、字体大小、字体样式线宽。我们可以使用带有所需属性名称的图例属性来修改它。  

方法

  • 导入模块
  • 绘制正态图
  • 相应地定制
  • 显示图

示例 1:

Python3
# import module
from bokeh.plotting import figure, show
 
# create data
currentList = [1, 2, 3, 4, 5]
List1 = [i*2 for i in currentList]
List2 = [i+2 for i in currentList]
 
# plot data
plots = figure(title=" your Legend Customization")
 
line = plots.line(
    currentList,
    List1,
    legend_label="Arrays .",
    line_color="blue",
    line_width=2
)
 
circle = plots.circle(
    currentList,
    List2,
    legend_label="List",
    fill_color="black",
    fill_alpha=0.4,
    line_color="blue",
    size=30,
)
 
# display legend in top right corner
plots.legend.location = "top_right"
 
# give title to legend
plots.legend.title = "Your observations"
 
# customize legend appearance
plots.legend.label_text_font = "times"
plots.legend.label_text_font_style = "italic"
plots.legend.label_text_color = "red"
 
# customize border and background of legend
plots.legend.border_line_width = 15
plots.legend.border_line_color = "pink"
plots.legend.border_line_alpha = 0.5
plots.legend.background_fill_color = "orange"
plots.legend.background_fill_alpha = 0.3
 
# display plot
show(plots)


Python3
# import module
from bokeh.plotting import figure, show
 
# create data
currentList = [1, 2, 3, 4, 5]
List1 = [i*2 for i in currentList]
List2 = [i+2 for i in currentList]
 
# plot data
plots = figure(title="Legend Customization")
 
line = plots.line(currentList,
                  List1,
                  legend_label="Arrays .",
                  line_color="blue",
                  line_width=2
                 )
 
circle = plots.circle(
    currentList,
    List2,
    legend_label="List",
    fill_color="black",
    fill_alpha=0.5,
    line_color="blue",
    size=40,
)
 
# display legend in top left corner
plots.legend.location = "top_left"
 
#give title to legend
plots.legend.title = "Observation of plot"
 
#customize legend appearance
plots.legend.label_text_font = "times"
plots.legend.label_text_font_style = "bold"
plots.legend.label_text_color = "black"
 
# customize border and background of legend
plots.legend.border_line_width = 9
plots.legend.border_line_color = "green"
plots.legend.border_line_alpha = 0.7
plots.legend.background_fill_color = "magenta"
plots.legend.background_fill_alpha = 0.2
 
show(plots)


Python3
# import module
from bokeh.plotting import figure, show
 
# create data
currentList = [1, 2, 3, 4, 5]
List1 = [i*2 for i in currentList]
List2 = [i+2 for i in currentList]
 
# plot data
plots = figure(title="Legend Customization")
 
line = plots.line(currentList,
                  List1,
                  legend_label="Arrays .",
                  line_color="blue",
                  line_width=2
                  )
 
circle = plots.circle(
    currentList,
    List2,
    legend_label="List",
    fill_color="black",
    fill_alpha=0.5,
    line_color="blue",
    size=50,
)
 
# display legend in top right corner
plots.legend.location = "top_center"
 
# give title to legend
plots.legend.title = " Your Observations "
 
# customize legend appearance
plots.legend.label_text_font = "times"
plots.legend.label_text_font_style = "normal"
plots.legend.label_text_color = "red"
 
# customize border and background of legend
plots.legend.border_line_width = 3
plots.legend.border_line_color = "grey"
plots.legend.border_line_alpha = 0.8
plots.legend.background_fill_color = "orange"
plots.legend.background_fill_alpha = 0.2
 
show(plots)


输出 :

示例 2:

蟒蛇3

# import module
from bokeh.plotting import figure, show
 
# create data
currentList = [1, 2, 3, 4, 5]
List1 = [i*2 for i in currentList]
List2 = [i+2 for i in currentList]
 
# plot data
plots = figure(title="Legend Customization")
 
line = plots.line(currentList,
                  List1,
                  legend_label="Arrays .",
                  line_color="blue",
                  line_width=2
                 )
 
circle = plots.circle(
    currentList,
    List2,
    legend_label="List",
    fill_color="black",
    fill_alpha=0.5,
    line_color="blue",
    size=40,
)
 
# display legend in top left corner
plots.legend.location = "top_left"
 
#give title to legend
plots.legend.title = "Observation of plot"
 
#customize legend appearance
plots.legend.label_text_font = "times"
plots.legend.label_text_font_style = "bold"
plots.legend.label_text_color = "black"
 
# customize border and background of legend
plots.legend.border_line_width = 9
plots.legend.border_line_color = "green"
plots.legend.border_line_alpha = 0.7
plots.legend.background_fill_color = "magenta"
plots.legend.background_fill_alpha = 0.2
 
show(plots)



输出 :

示例 3:

蟒蛇3

# import module
from bokeh.plotting import figure, show
 
# create data
currentList = [1, 2, 3, 4, 5]
List1 = [i*2 for i in currentList]
List2 = [i+2 for i in currentList]
 
# plot data
plots = figure(title="Legend Customization")
 
line = plots.line(currentList,
                  List1,
                  legend_label="Arrays .",
                  line_color="blue",
                  line_width=2
                  )
 
circle = plots.circle(
    currentList,
    List2,
    legend_label="List",
    fill_color="black",
    fill_alpha=0.5,
    line_color="blue",
    size=50,
)
 
# display legend in top right corner
plots.legend.location = "top_center"
 
# give title to legend
plots.legend.title = " Your Observations "
 
# customize legend appearance
plots.legend.label_text_font = "times"
plots.legend.label_text_font_style = "normal"
plots.legend.label_text_color = "red"
 
# customize border and background of legend
plots.legend.border_line_width = 3
plots.legend.border_line_color = "grey"
plots.legend.border_line_alpha = 0.8
plots.legend.background_fill_color = "orange"
plots.legend.background_fill_alpha = 0.2
 
show(plots)

输出