Skip to content

Instantly share code, notes, and snippets.

@seahawk1986 seahawk1986/example1.py Secret
Last active Aug 23, 2018

Embed
What would you like to do?
Pandas mit matplotlib als Alternative zu gnuplot - basierend auf den Beispielen aus https://www.my-it-brain.de/wordpress/ein-gnuplot-tutorial
#!/usr/bin/env python3
import pandas as pd
my_cols = ['Berichtsjahr', 'leichtes Heizöl [Cent/l]', 'Strom [Cent/kWh]']
df = pd.read_csv('http://www.my-it-brain.de/wordpress/wp-content/uploads/2018/08/Energiepreise_Heizoel_Strom.csv',
sep=';', names=my_cols, skiprows=5, decimal=",")
df['Berichtsjahr'] = pd.to_datetime(df['Berichtsjahr'], format="%Y")
plot = df.plot(x='Berichtsjahr', y=['leichtes Heizöl [Cent/l]', 'Strom [Cent/kWh]'],
style=['bs-','ro-'])
plot.set_ylabel("Preis in Cents")
plot.grid()
fig = plot.get_figure()
fig.savefig('/tmp/example1.svg')
#!/usr/bin/env python3
import pandas as pd
my_cols = ["Date", "Temperatur 1", "Humidity 1", "Temperatur 2", "Humidity 2", "Temperatur 3", "Humidity 3"]
df = pd.read_csv('http://www.my-it-brain.de/wordpress/wp-content/uploads/2018/08/dht22data.csv',
names=my_cols, skiprows=1)
df['Date'] = pd.to_datetime(df['Date'], errors='coerce')
df['Temperatur 3'] = pd.to_numeric(df['Temperatur 3'], errors='coerce')
plot = df.plot(x='Date',figsize=(20,10), secondary_y=['Humidity 1', 'Humidity 2', 'Humidity 3'], style='.', ms=1)
plot.set_xlim(pd.Timestamp('2018-06-04T17:57:26'), pd.Timestamp('2018-07-11T12:44:50'))
plot.set_ylabel("Temperatur [°C]")
plot.right_ax.set_ylabel("Humidity [%]")
plot.grid()
legend = plot.get_legend()
legend.set_bbox_to_anchor((1.15, 1))
for legend_handle in legend.legendHandles: legend_handle._legmarker.set_markersize(10)
fig = plot.get_figure()
fig.savefig('/tmp/plot_example2.svg')
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.