by Anonymous » 09 Mar 2025, 11:41
Versuchen Sie, ein animiertes GIF mit statischen Bildern aus der Seeborn -Bibliothek zu erstellen.
Der Code lautet wie folgt: < /p>
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
import imageio.v3 as iio
image = []
folder = 'C:/Users/admin/PycharmProjects/pythonProject2/Project/Seaborn'
if not os.path.exists(folder):
os.mkdir(folder)
for month in range(1, 4):
porosity_cutoff = 250
highlight_colour = 8
non_highlight_colour = 10
df = pd.read_csv('../Список.csv')
df = df.loc[df['Месяц'] == month].sort_values(by='Баллы', ascending=False)
df['colours'] = df["Баллы"].apply(lambda x: highlight_colour if x >= porosity_cutoff else non_highlight_colour)
ax = sns.barplot(data=df.loc[df['Месяц'] == month], x="Баллы", y="Участники", palette="Set1", hue=df['colours'],
legend=False)
plt.axvline(x=250, zorder=0, color='grey', ls='--', lw=1.5)
plt.text(x=283, y=8, s='Порог допустимых баллов', ha='center', fontsize=11, bbox=dict(facecolor='white',
edgecolor="grey", ls='--'))
ax.set_title(f"Рейтинг за {month} месяц", size=30)
ax.set_ylabel("Участники", size=20)
ax.set_xlabel("Баллы", size=20)
for i in ax.containers:
ax.bar_label(i, color="white", padding=-30, fontsize=12)
filename = f'Рейтинг_{month}.png'
plt.savefig(filename)
image.append(iio.imread(filename))
plt.close()
iio.imwrite('barplot.gif', image, duration=20)
< /code>
Am Ende erhalte ich drei Bilder im PNG -Format mit Grafiken, alle Bilder sind korrekt, aber die Giftcard selbst ist ein statisches erstes Diagramm. Was kann geändert werden oder funktioniert im Allgemeinen nicht?>
Versuchen Sie, ein animiertes GIF mit statischen Bildern aus der Seeborn -Bibliothek zu erstellen.
Der Code lautet wie folgt: < /p>
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
import imageio.v3 as iio
image = []
folder = 'C:/Users/admin/PycharmProjects/pythonProject2/Project/Seaborn'
if not os.path.exists(folder):
os.mkdir(folder)
for month in range(1, 4):
porosity_cutoff = 250
highlight_colour = 8
non_highlight_colour = 10
df = pd.read_csv('../Список.csv')
df = df.loc[df['Месяц'] == month].sort_values(by='Баллы', ascending=False)
df['colours'] = df["Баллы"].apply(lambda x: highlight_colour if x >= porosity_cutoff else non_highlight_colour)
ax = sns.barplot(data=df.loc[df['Месяц'] == month], x="Баллы", y="Участники", palette="Set1", hue=df['colours'],
legend=False)
plt.axvline(x=250, zorder=0, color='grey', ls='--', lw=1.5)
plt.text(x=283, y=8, s='Порог допустимых баллов', ha='center', fontsize=11, bbox=dict(facecolor='white',
edgecolor="grey", ls='--'))
ax.set_title(f"Рейтинг за {month} месяц", size=30)
ax.set_ylabel("Участники", size=20)
ax.set_xlabel("Баллы", size=20)
for i in ax.containers:
ax.bar_label(i, color="white", padding=-30, fontsize=12)
filename = f'Рейтинг_{month}.png'
plt.savefig(filename)
image.append(iio.imread(filename))
plt.close()
iio.imwrite('barplot.gif', image, duration=20)
< /code>
Am Ende erhalte ich drei Bilder im PNG -Format mit Grafiken, alle Bilder sind korrekt, aber die Giftcard selbst ist ein statisches erstes Diagramm. Was kann geändert werden oder funktioniert im Allgemeinen nicht?>