简体   繁体   English

您如何关闭(或隐藏)openpyxl 中组合图表上的秒 y 轴刻度?

[英]How do you turn off (or hide) the seconds y axis scale on a combination chart in openpyxl?

How do you turn off (or hide) the seconds y axis scale on a combination chart in openpyxl?您如何关闭(或隐藏)openpyxl 中组合图表上的秒 y 轴刻度?

I can find the xml difference by comparing the before and after changes to hide the scale (I just change the excel file extension to '.zip' to access the xml):我可以通过比较前后更改以隐藏比例来找到 xml 差异(我只是将 excel 文件扩展名更改为“.zip”以访问 xml):

    -<c:valAx>
<c:axId val="156672520"/>
-<c:scaling>
<c:orientation val="minMax"/>
</c:scaling>
<c:delete val="0"/>
<c:axPos val="r"/>
<c:majorGridlines/>
<c:numFmt sourceLinked="1" formatCode="0.0"/>
<c:majorTickMark val="out"/>
<c:minorTickMark val="none"/>
<c:tickLblPos val="none"/>     # this changes from 'nextTo'
<c:crossAx val="207247000"/>
<c:crosses val="max"/>
<c:crossBetween val="between"/>
</c:valAx>

I've tried this (last few lines are the 'tickLblPos' ):我试过这个(最后几行是 'tickLblPos' ):

    mainchart = LineChart()
mainchart.style = 12
v2 = Reference(WorkSheetOne, min_col=1, min_row=2+CombBarLineDataOffsetFromTop, max_row=3+CombBarLineDataOffsetFromTop, max_col=13)
mainchart.add_data(v2, titles_from_data=True, from_rows=True)

mainchart.layout = Layout(
    ManualLayout(
    x=0.12, y=0.25, # position from the top
    h=0.9, w=0.75, # this is scaling the chart into the container
    xMode="edge",
    yMode="edge",
    )
)

mainchart.title = "Chart Title"

# Style the lines
s1 = mainchart.series[0]
#Marker type
s1.marker.symbol = "diamond" # triangle
s1.marker.size = 9
s1.marker.graphicalProperties.solidFill = "C00000" # Marker filling
s1.marker.graphicalProperties.line.solidFill = "000000" # Marker outline
s1.graphicalProperties.line.noFill = False
# Line color
s1.graphicalProperties.line.solidFill = "000000" # line color

s2 = mainchart.series[1]
s2.graphicalProperties.line.solidFill = "000000" 
s2.graphicalProperties.line.dashStyle = "dash"

mainchart.dataLabels = DataLabelList()

mainchart.dataLabels.showVal = False
mainchart.dataLabels.dLblPos = 't' 
mainchart.height = 15 
mainchart.width = 39 

#Create the Chart
chart2 = BarChart()
chart2.type = "col"
chart2.style = 10  # simple bar
chart2.y_axis.axId = 0

dataone = Reference(WorkSheetOne, min_col=2, min_row=CombBarLineDataOffsetFromTop+1, max_row=CombBarLineDataOffsetFromTop+1, max_col=13 )
doneseries = Series(dataone, title="Series Title")
chart2.append(doneseries)


cats = Reference(WorkSheetOne, min_col=2, min_row=CombBarLineDataOffsetFromTop, max_row=CombBarLineDataOffsetFromTop, max_col=13)
chart2.set_categories(cats)

# Set the series for the chart data
series3Total = chart2.series[0]
fill3Total =  PatternFillProperties(prst="pct5")
fill3Total.foreground = ColorChoice(srgbClr='996633') # brown
fill3Total.background = ColorChoice(srgbClr='996633')
series3Total.graphicalProperties.pattFill = fill3Total

chart2.dataLabels = DataLabelList()
chart2.dataLabels.showVal = False 
chart2.shape = 2 

mainchart.y_axis.crosses = "max"
mainchart.y_axis.tickLblPos = "none" # nextTo -- this doesn't work

mainchart += chart2

WorkSheetOne.add_chart(mainchart, 'A1')

How can I translate the difference in the XML to an attribute with openpyxl?如何使用 openpyxl 将 XML 中的差异转换为属性?

The problem here is with some of default values for some attributes which use 3-valued logic at times so that None != "none" , ie.这里的问题是某些属性的一些默认值有时使用 3 值逻辑,因此None != "none" ,即。 <c:tickLblPos /> != <c:tickLblPos val="none"/> because the default is "nextTo". <c:tickLblPos /> != <c:tickLblPos val="none"/>因为默认是“nextTo”。 This plays havoc with the Python semantics (3-valued logic is always wrong) where the default is not to set an attribute if the value is None in Python.这对 Python 语义造成了严重破坏(3 值逻辑总是错误的),如果 Python 中的值为None ,则默认不设置属性。 This really only affects ChartML and I've added some logic to the descriptors for the relevant objects so that "none" will be written where required.这实际上只影响 ChartML,我已经为相关对象的描述符添加了一些逻辑,以便在需要的地方写入“none”。

But this code isn't publicly available yet.但此代码尚未公开可用。 Get in touch with my by e-mail if you'd like a preview.如果您想预览,请通过电子邮件与我联系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM