Chart - Legend¶
A chart may have a legend. The legend may be placed within the plot area or alongside it. The legend has a fill and font and may be positioned on the top, right, bottom, left, in the upper-right corner, or in a custom position. Individual legend entries may be custom specified, but that is not yet in scope.
Candidate protocol¶
>>> chart.has_legend
False
>>> chart.has_legend = True
>>> chart.has_legend
True
>>> legend = chart.legend
>>> legend
<pptx.chart.chart.Legend object at 0xdeadbeef1>
>>> legend.font
<pptx.text.Font object at 0xdeadbeef2>
>>> legend.horz_offset
0.0
>>> legend.horz_offset = 0.2
>>> legend.horz_offset
0.2
>>> legend.include_in_layout
True
>>> legend.include_in_layout = False
>>> legend.include_in_layout
False
>>> legend.position
XL_LEGEND_POSITION.RIGHT (-4152)
>>> legend.position = XL_LEGEND_POSITION.BOTTOM
>>> legend.position
XL_LEGEND_POSITION.BOTTOM (-4107)
Feature Summary¶
Chart.has_legend
– Read/write boolean propertyChart.legend
– Read-onlyLegend
object or NoneLegend.horz_offset
– Read/write float (-1.0 -> 1.0).Legend.include_in_layout
– Read/write boolean.Legend.position
– Read/write XL_LEGEND_POSITIONLegend.font
– Read-onlyFont
object.
Enumerations¶
Microsoft API¶
- Chart.HasLegend
True if the chart has a legend. Read/write Boolean.
- Chart.Legend
Returns the legend for the chart. Read-only Legend.
- Legend.IncludeInLayout
True if a legend will occupy the chart layout space when a chart layout is being determined. The default is True. Read/write Boolean.
- Legend.Position
Returns or sets the position of the legend on the chart. Read/write XlLegendPosition.
XML specimens¶
Example legend XML:
<c:legend>
<c:legendPos val="t"/>
<c:layout>
<c:manualLayout>
<c:xMode val="edge"/>
<c:yMode val="edge"/>
<c:x val="0.321245570866142"/>
<c:y val="0.025"/>
<c:w val="0.532508858267717"/>
<c:h val="0.0854055118110236"/>
</c:manualLayout>
</c:layout>
<c:overlay val="1"/>
<c:spPr>
<a:solidFill>
<a:schemeClr val="accent6">
<a:lumMod val="20000"/>
<a:lumOff val="80000"/>
</a:schemeClr>
</a:solidFill>
</c:spPr>
<c:txPr>
<a:bodyPr/>
<a:lstStyle/>
<a:p>
<a:pPr>
<a:defRPr sz="1600" b="0" i="1" baseline="0"/>
</a:pPr>
<a:endParaRPr lang="en-US"/>
</a:p>
</c:txPr>
</c:legend>
Legend having horz_offset == 0.42:
<c:legend>
<c:legendPos val="r"/>
<c:layout>
<c:manualLayout>
<c:xMode val="factor"/>
<c:yMode val="factor"/>
<c:x val="0.42"/>
</c:manualLayout>
</c:layout>
<c:overlay val="0"/>
</c:legend>