python - 如何向包含两个系列的图表添加图例?
问题描述
以下脚本创建一个包含两列的工作表。从这两列中,我创建了一个图表。然后我尝试在轴的右侧放置一个图例,但由于某种原因看不到图例。你能告诉我为什么我看不到传说吗?
顺便说一句,我已经尝试过没有任何成功的方法(其中一个被标记为注释)
chart = LineChart()
chart.title = "Device Time drift (2 samples/hour)"
chart.legend.position = 'r'
# chart.legend.layout = Layout(
# manualLayout=ManualLayout(
# yMode='edge',
# xMode='edge',
# x=0, y=0.9,
# h=0.1, w=0.5
# )
# )
chart.style = 10
chart.y_axis.title = 'Time Delta [mSec]'
chart.x_axis.title = 'Sample No.'
chart.legend = None
chart.height = 20 # default is 7.5
chart.width = 40 # default is 15
font = Font(typeface='Verdana')
size = 1200 # 14 point size
cp = CharacterProperties(latin=font, sz=size, b=False) # Not bold
pp = ParagraphProperties(defRPr=cp)
# X and Y axes titles
chart.x_axis.title.tx.rich.p[0].pPr = pp
chart.y_axis.title.tx.rich.p[0].pPr = pp
data = Reference(worksheet=ws_write_timedel, min_col=1, min_row=1,
max_row=len(ws_write_timedel['A']), max_col=2, )
chart.add_data(data, titles_from_data=True,)
s1 = chart.series[0]
s1.graphicalProperties.line.solidFill = "00AAAA"
s1.graphicalProperties.line.dashStyle = "sysDot"
s1.graphicalProperties.line.width = 100050 # width in EMUs
s2 = chart.series[1]
s2.smooth = True
ws_write_timedel.add_chart(chart, "D1")enter code here
解决方案
以下脚本是固定版本,现在图例已添加到图表中
chart = LineChart()
chart.title = "Device Time drift (2 samples/hour)"
chart.legend.position = 'r'
chart.style = 10
chart.y_axis.title = 'Time Delta [mSec]'
chart.x_axis.title = 'Sample No.'
chart.height = 20 # default is 7.5
chart.width = 40 # default is 15
font = Font(typeface='Verdana')
size = 1200 # 14 point size
cp = CharacterProperties(latin=font, sz=size, b=False) # Not bold
pp = ParagraphProperties(defRPr=cp)
# X and Y axes titles
chart.x_axis.title.tx.rich.p[0].pPr = pp
chart.y_axis.title.tx.rich.p[0].pPr = pp
data = Reference(worksheet=ws_write_timedel, min_col=1, min_row=1,
max_row=len(ws_write_timedel['A']), max_col=2, )
chart.add_data(data, titles_from_data=True,)
s1 = chart.series[0]
s1.graphicalProperties.line.solidFill = "00AAAA"
s1.graphicalProperties.line.dashStyle = "sysDot"
s1.graphicalProperties.line.width = 100050 # width in EMUs
s2 = chart.series[1]
s2.smooth = True
ws_write_timedel.add_chart(chart, "D1")enter code here
推荐阅读
- mysql - 仅使用 VueJs 连接到数据库
- python - 如何遍历 JSON 对象?
- html - Xamarin 中的 Razor 模板
- html - 从外部样式表调用时未应用 CSS
- apache-beam - Apache Beam ValueProvider 的 Python 类型提示
- shell - 在两个单词之间应用最长的空格不起作用
- ios - 从 SwiftUI 中的异步线程返回值以与 fileExporter 一起使用
- flutter - 由于底部导航栏和标签栏导致底部溢出
- reactjs - 如何显示/隐藏使用材料-ui
- android - AudioManager - 有没有办法获得相关的音频流?