pyvista.Renderer.add_legend

pyvista.Renderer.add_legend#

Renderer.add_legend(
labels=None,
bcolor=None,
border=False,
size=(0.2, 0.2),
name=None,
loc='upper right',
face=None,
font_family=None,
background_opacity=1.0,
)[ソース]#

凡例をレンダリングウィンドウに追加します.

エントリは,項目ごとに1つの文字列とカラーエントリを含みますリストである必要があります.

パラメータ:
labelslist | dict, optional

None に設定すると,次で指定した既存のラベルが使用されます.

For dict inputs, the keys are used as labels and the values are used as the colors. Labels must be strings, and colors can be any ColorLike.

For list inputs, the list must contain one entry for each item to be added to the legend. Each entry can contain one of the following:

  • 2つの文字列 ([label, color]) , label は追加するアイテムの名前, color は追加するラベルの色.

  • Three strings ([label, color, face]) where label is the name of the item to add, color is the color of the label to add, and face is a string which defines the face (i.e. circle, triangle, box, etc.). face could be also "none" (no face shown for the entry), or a pyvista.PolyData.

  • キー label を持つ辞書.オプションでキー colorface を追加することもできます.これらのキーの値は文字列にすることができます. face キーの場合, pyvista.PolyData にすることもできます.

bcolorColorLike, default: (0.5, 0.5, 0.5)

背景色.3つの項目0から1のRGBカラーリスト,またはmatplotlibカラー文字列(例:白色の場合は 'w' または 'white' )のいずれかです.Noneの場合,凡例の背景は使用不可になります.

borderbool, default: False

凡例の周囲に境界線を表示するかどうかをコントロールします.デフォルトはFalseです.

sizesequence[float], default: (0.2, 0.2)

2つの浮動小数点シーケンスで,それぞれが0と1の間の浮動小数点です.たとえば, (0.1, 0.1) と指定すると,凡例は図形ウィンドウ全体のサイズの10%のサイズになります.

namestr, optional

簡単に更新できるように,追加したアクターの名前.この名前のアクターがレンダリングウィンドウに既に存在する場合は,新しいアクターに置き換えられます.

locstr, default: "upper right"

位置情報の文字列です. 以下のいずれかになります:

  • 'upper right'

  • 'upper left'

  • 'lower left'

  • 'lower right'

  • 'center left'

  • 'center right'

  • 'lower center'

  • 'upper center'

  • 'center'

facestr | pyvista.PolyData, optional

Face shape of legend face. Defaults to a triangle for most meshes, with the exception of glyphs where the glyph is shown (e.g. arrows).

You may set it to one of the following:

  • None: "none"

  • 線: "-""line"

  • 3角形: "^"'triangle'

  • 円: "o"'circle'

  • 長方形: "r"'rectangle'

  • カスタム: pyvista.PolyData

Passing "none" removes the legend face. A custom face can be created using pyvista.PolyData. This will be rendered from the XY plane.

font_familystr, optional

フォントファミリ. 'courier', 'times', または arial'`` のいずれかでなければなりません.デフォルトは pyvista.global_theme.font.family です.

background_opacityfloat, default: 1.0

背景の不透明度を設定します.

戻り値:
vtkLegendBoxActor

凡例のアクター.

add_mesh を使用する際に,メッシュにラベルを付けて凡例を作成します.

>>> import pyvista as pv
>>> from pyvista import examples
>>> sphere = pv.Sphere(center=(0, 0, 1))
>>> cube = pv.Cube()
>>> plotter = pv.Plotter()
>>> _ = plotter.add_mesh(
...     sphere, color='grey', smooth_shading=True, label='Sphere'
... )
>>> _ = plotter.add_mesh(cube, color='r', label='Cube')
>>> _ = plotter.add_legend(bcolor='w', face=None)
>>> plotter.show()
../../../_images/pyvista-Renderer-add_legend-1_00_00.png

Alternatively provide labels in the plotter as a list.

>>> plotter = pv.Plotter()
>>> _ = plotter.add_mesh(sphere, color='grey', smooth_shading=True)
>>> _ = plotter.add_mesh(cube, color='r')
>>> legend_entries = []
>>> legend_entries.append(['My Mesh', 'w'])
>>> legend_entries.append(['My Other Mesh', 'k'])
>>> _ = plotter.add_legend(legend_entries)
>>> plotter.show()
../../../_images/pyvista-Renderer-add_legend-1_01_00.png

Or use a dictionary to define them.

>>> labels = {'Grey Stuff': 'grey', 'Red Stuff': 'red'}
>>> plotter = pv.Plotter()
>>> _ = plotter.add_mesh(sphere, color='grey', smooth_shading=True)
>>> _ = plotter.add_mesh(cube, color='red')
>>> _ = plotter.add_legend(labels, face='rectangle')
>>> plotter.show()
../../../_images/pyvista-Renderer-add_legend-1_02_00.png