介绍对于xy轴网格线、标签等的操作
import openpyxl
from openpyxl.chart import LineChart, Reference,Series
from openpyxl.chart.axis import ChartLines
from openpyxl.chart.layout import Layout,ManualLayout
from openpyxl.chart.shapes import GraphicalProperties
from openpyxl.drawing.text import CharacterProperties
def()
chart.title = "折线图"
chart.x_axis.title = "x"
chart.x_axis.title.tx.rich.p[0].pPr.defRPr = CharacterProperties(sz=1400) #设置x轴标题字体大小
chart.y_axis.title = "y"
chart.y_axis.title.tx.rich.p[0].pPr.defRPr = CharacterProperties(sz=1400) #设置y轴标题字体大小
chart.x_axis.tickLblPos = 'low' # x轴标签位置
chart.x_axis.tickLblSkip = 20 # x轴标签间隔
chart.x_axis.tickMarkSkip = 20 # x轴刻度线间隔
chart.y_axis.scaling.logBase = 10 # y轴对数刻度
chart.y_axis.number_format = '0.0E+00' # y轴数据按科学计数法显示格式为‘0.0e+00’
chart.y_axis.minorGridlines = ChartLines() # y轴显示次要网格线
chart.x_axis.majorGridlines = ChartLines() # x轴显示主要网格线
chart.y_axis.majorGridlines.spPr = GraphicalProperties(solidFill="000000") # y轴主要网格线设置为黑色
chart.y_axis.majorGridlines.graphicalProperties.line.solidFill = "000000" # y轴主要网格线设置为黑色
chart.y_axis.minorGridlines.spPr = GraphicalProperties(solidFill="808080") # y轴次要网格线颜色为‘808080’
chart.y_axis.minorGridlines.graphicalProperties.line.dashStyle = "lgDash" # y轴次要网格线线型
chart.y_axis.minorGridlines.graphicalProperties.line.solidFill = "808080" # y轴次要网格线颜色
chart.x_axis.majorGridlines.spPr = GraphicalProperties(solidFill="808080")
chart.x_axis.majorGridlines.graphicalProperties.line.dashStyle = "dash" #x轴主要网格线线型
chart.width = 30 # 图表宽度
chart.height = 15 # 图表高度
chart.layout = Layout(manualLayout=ManualLayout(yMode='edge',xMode='edge',x=0.04,y=0.1,h=0.8,w=0.65)) #曲线在整个图中的占比
chart.legend.layout = Layout(manualLayout=ManualLayout(yMode='edge', xMode='edge', x=0.71, y=0.05, h=0.9, w=0.28)) #图例在整个图中的占比
# 创建一个 LineChart 对象
chart = LineChart()
# 配置图表
chart.title = "折线图"
chart.x_axis.title = "x"
chart.x_axis.title.tx.rich.p[0].pPr.defRPr = CharacterProperties(sz=1400) #设置x轴标题字体大小
chart.y_axis.title = "y"
chart.y_axis.title.tx.rich.p[0].pPr.defRPr = CharacterProperties(sz=1400) #设置y轴标题字体大小
chart.x_axis.tickLblPos = 'low' # x轴标签位置
chart.x_axis.tickLblSkip = 20 # x轴标签间隔
chart.x_axis.tickMarkSkip = 20 # x轴刻度线间隔
chart.y_axis.scaling.logBase = 10 # y轴对数刻度
chart.y_axis.number_format = '0.0E+00' # y轴数据按科学计数法显示格式为‘0.0e+00’
chart.y_axis.minorGridlines = ChartLines() # y轴显示次要网格线
chart.x_axis.majorGridlines = ChartLines() # x轴显示主要网格线
chart.y_axis.majorGridlines.spPr = GraphicalProperties(solidFill="000000") # y轴主要网格线设置为黑色
chart.y_axis.majorGridlines.graphicalProperties.line.solidFill = "000000" # y轴主要网格线设置为黑色
chart.y_axis.minorGridlines.spPr = GraphicalProperties(solidFill="808080") # y轴次要网格线颜色为‘808080’
chart.y_axis.minorGridlines.graphicalProperties.line.dashStyle = "lgDash" # y轴次要网格线线型
chart.y_axis.minorGridlines.graphicalProperties.line.solidFill = "808080" # y轴次要网格线颜色
chart.x_axis.majorGridlines = ChartLines()
chart.x_axis.majorGridlines.spPr = GraphicalProperties(solidFill="808080")
chart.x_axis.majorGridlines.graphicalProperties.line.dashStyle = "dash" #x轴主要网格线线型
chart.width = 30 # 图表宽度
chart.height = 15 # 图表高度
chart.layout = Layout(manualLayout=ManualLayout(yMode='edge',xMode='edge',x=0.04,y=0.1,h=0.8,w=0.65)) #曲线在整个图中的占比
chart.legend.layout = Layout(manualLayout=ManualLayout(yMode='edge', xMode='edge', x=0.71, y=0.05, h=0.9, w=0.28)) #图例在整个图中的占比