以下は、コードと、Python の Openpyxl パッケージを使用して生成された結果の Excel チャートです。
また、以下はグラフです。結果を次のようにしたいのですが、次のことをグラフに追加するにはどうすればよいですか? 追加したいグラフの機能を赤で囲みました。
グラフの X 軸に伸びる各データ ポイントからの長方形の破線。
2 つの個別のフォント/サイズによる左揃えのタイトル配置 (「タイトル」用の 1 つのフォント セット、「タイトル 2」および「タイトル 3」用の個別のフォント セット)
グラフの下にある複数のフローティング テキスト ボックス (下部の注 1、2、3 を参照)
コード
import openpyxl
from openpyxl.chart import LineChart,Reference
from openpyxl.chart.label import DataLabelList
from openpyxl.chart.text import RichText
from openpyxl.drawing.text import Paragraph, ParagraphProperties, CharacterProperties, Font
excel = "Template.xlsx"
excel_file = openpyxl.load_workbook(excel)
Output_Sheet = excel_file.get_sheet_by_name('Sheet1')
excel_file.save("Template2.xlsx")
#Define data
data = Reference(Output_Sheet, min_col = 25, min_row = 5,
max_col = 25, max_row = 15)
#Define category
categories = Reference(Output_Sheet, min_col = 23, min_row = 5,
max_col = 24, max_row = 15)
#Initialize
chart = LineChart()
#add Data
chart.add_data(data)
#Add category
chart.set_categories(categories)
#Define title
chart.title = " Title \n Title2 \n Title3"
# set the title of the x-axis
# set the title of the y-axis
chart.y_axis.title = "Revenue "
#Define chart and font
font_test = Font(typeface='Avenir LT Std 55 Roman')
cp = CharacterProperties(latin=font_test, sz=1500)
chart.x_axis.txPr = RichText(p=[Paragraph(pPr=ParagraphProperties(defRPr=cp), endParaRPr=cp)])
chart.y_axis.txPr = RichText(p=[Paragraph(pPr=ParagraphProperties(defRPr=cp), endParaRPr=cp)])
chart.title.txPr = RichText(p=[Paragraph(pPr=ParagraphProperties(defRPr=cp), endParaRPr=cp)])
#Size
chart.height = 17.5 # default is 7.5
chart.width = 40 # default is 15
#Remove legend
chart.legend = None
s2 = chart.series[0]
s2.smooth = True # Make the line smooth
#Show Data Label
chart.dataLabels = DataLabelList()
chart.dataLabels.showVal = True
#Define font and size
font_test = Font(typeface='Avenir LT Std 55 Roman')
cp = CharacterProperties(latin=font_test, sz=750)
chart.dataLabels.txPr = RichText(p=[Paragraph(pPr=ParagraphProperties(defRPr=cp), endParaRPr=cp)])
#Add Chart
Output_Sheet.add_chart(chart, "B18")
# save the file
excel_file.save("Template2.xlsx")
電流出力

望ましい出力
