forked from Silias-Public/Sonnendach
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
|
|
def create_barchart(barChartMonth, barChartData, color, image_folder_barcharts, image_filename):
|
|
barChartMonth.reverse()
|
|
barChartData.reverse()
|
|
|
|
max_wert = max(barChartData)
|
|
min_wert = min(barChartData)
|
|
skala = max_wert + max_wert * 0.1
|
|
|
|
plt.figure(figsize=(7, 3))
|
|
plt.bar(barChartMonth, barChartData, color=color)
|
|
|
|
plt.ylabel('Stromproduktion in Franken', fontsize=12)
|
|
|
|
plt.ylim(0, skala)
|
|
|
|
# Turn off the frame (border) around the graphic
|
|
ax = plt.gca() # Get the current axis
|
|
ax.spines['top'].set_visible(False)
|
|
ax.spines['right'].set_visible(False)
|
|
ax.spines['bottom'].set_visible(False)
|
|
|
|
plt.xticks(barChartMonth)
|
|
# Set the x-axis limits to remove extra space on the right
|
|
# plt.xlim(barChartMonth[0], barChartMonth[-1])
|
|
|
|
plt.savefig(f"{image_folder_barcharts}{image_filename}", bbox_inches='tight')
|
|
plt.show()
|
|
|
|
|
|
barChartMonth = [8, 7, 6, 5, 4, 3, 2, 1, 12, 11, 10, 9]
|
|
barChartMonth = [str(item) for item in barChartMonth]
|
|
|
|
barChartData=[612.9508602242413, 774.9497310367794, 905.1661458663121, 700.3920174038531, 455.8453881411557, 362.9725109507848, 243.91420489011418, 106.40652073925607, 98.73508056571949, 140.51124465669344, 293.31970563938467, 442.59112071461107]
|
|
image_folder_barcharts = "barcharts/"
|
|
image_filename = "test-file.png"
|
|
color = "red"
|
|
create_barchart(barChartMonth, barChartData, color, image_folder_barcharts, image_filename) |