我有以下pandas dataframe:
df = pd.DataFrame({
'Festzelt': ["Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Hacker-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt", "Löwenbräu-Festzelt"],
'Biermenge': [1.068510948, 1.111444388, 1.097928649, 1.097319892, 1.112046892, 1.096458863, 1.098193952, 1.105528912, 1.081012023, 1.096862587, 1.096820787, 1.112483864, 1.090409846, 1.076176749, 1.05914969, 1.111281072, 1.090280455, 1.071867235, 1.104982445, 1.074247709, 1.103154487, 1.136741808, 1.051554041, 1.089669195, 1.126347645, 1.105658808, 1.117330659, 1.101642591, 1.065208517, 1.082705561, 1.081997508, 1.100248942, 1.102306684, 1.106034801, 1.061078385, 1.065105824, 1.118714312, 1.103743509, 1.10806331, 1.127161842, 1.095313864, 1.083297614, 1.088053678, 1.096490414, 1.103947732, 1.070520785, 1.096987797, 1.045452588, 1.097941923, 1.087059407, 1.059211299, 1.004684239, 0.998865106, 1.011393955, 1.020030032, 1.000917207, 1.037486604, 1.058419981, 0.999914939, 1.037276828, 1.011935826, 1.00550927, 1.035434798, 1.049929295, 1.023505819, 1.04547058, 1.019198865, 1.01983709, 1.011544282, 1.019780386, 1.001639294, 1.027859424, 1.060448349, 1.047727746, 1.020635143, 1.030990766, 1.003855964, 1.024180945, 1.033970302, 1.024973412, 1.046135278, 1.031333533, 1.037277845, 1.023052959, 1.046540625, 1.014640256, 1.009600155, 0.988617146, 0.993939951, 1.019822804, 0.980809392, 1.034884526, 1.039759923, 1.019183791, 0.980610209, 1.015745219, 0.982644572, 1.019548832, 1.03694442, 0.984112046],
})
并需要这样的输出:
我有以下代码,它几乎是我想要的:
import pandas as pd
import matplotlib.pyplot as plt
from charts.basechart import BaseChart
from charts.constants import FIGURE_SIZE_DEFAULT, TITLE_FONT_SIZE, COLORS, MARKERS, LINES
class Timeseriesplot2(BaseChart):
def process(self):
title = self.chart.config.title
# Define data and parameters
df = pd.DataFrame(self.chart.data)
plt.figure(figsize=FIGURE_SIZE_DEFAULT)
# Loop over pd an genrate plots
for (index, column) in enumerate(df):
y = df[column]
x = range(1, df[column].count() + 1)
count = df[column].count()
plt.plot((x + (index * count)), y,
linestyle=LINES[index], marker=MARKERS[index], color=COLORS[index], label=df.columns[index])
plt.legend(loc='best')
plt.title(title, fontsize=TITLE_FONT_SIZE, pad=20)
# Grid lines
plt.grid()
return plt
但我需要像上图中那样分开的组。并且时间序列应该在与dataframe列中的位置的索引相关的索引的全范围中开始和结束。
我希望解释清楚。
每一个帮助都是值得赞赏的!
1条答案
按热度按时间vatpfxk51#
我会将代码简化为如下内容:
输出: