| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

问题点数：0 回复次数：2

import xlrd
import os
from openpyxl import Workbook
from openpyxl.chart import (
ScatterChart,
Reference,
Series,
)

chart = ScatterChart()#散点图

chart.title = list_1[0][n]
chart.style = 13
chart.linewidths=1

from openpyxl import Workbook
from openpyxl.chart import (
ScatterChart,
Reference,
Series,
)
wb = Workbook()
ws = wb.active
rows = [
['Size', 'Batch 1', 'Batch 2'],
[2, 40, 30],
[3, 40, 25],
[4, 50, 30],
[5, 30, 25],
[6, 25, 35],
[7, 20, 40],
]
for row in rows:
ws.append(row)
chart = ScatterChart()
chart.title = "Scatter Chart"
chart.style = 10
chart.x_axis.title = 'Size'
chart.y_axis.title = 'Percentage'
xvalues = Reference(ws, min_col=1, min_row=2, max_row=7)
for i in range(2, 4):
values = Reference(ws, min_col=i, min_row=1, max_row=7)
series = Series(values, xvalues, title_from_data=True)
chart.series.append(series)
# 第一条散点
s1 = chart.series[0]
# 散点标记类型  'auto', 'dash', 'triangle', 'square', 'picture', 'circle', 'dot', 'plus', 'star', 'diamond', 'x'
s1.marker.symbol = "circle"
s1.marker.graphicalProperties.solidFill = "0000FF"  # Marker filling 设定标记填充的颜色
s1.marker.graphicalProperties.line.solidFill = "0000FF"  # Marker outline 标记轮廓的颜色
s1.graphicalProperties.line.noFill = True  # 关闭连线填充
# 第二条带连线的散点
s2 = chart.series[1]
s2.marker.symbol = "circle"
s2.graphicalProperties.solidFill = "FF0000"
s2.marker.graphicalProperties.line.solidFill = "FF0000"
s2.graphicalProperties.dashStyle = "dash"
s2.graphicalProperties.line.width = 5000  #控制线条的粗细
ws.add_chart(chart, "A10")
wb.save("scatter1.xlsx")

• 3
• 1/1页
• 1

Powered by Discuz, Processed in 0.051131 second(s), 8 queries.
Copyright©2004-2021, BCCN.NET, All Rights Reserved