Seite 1 von 1

Python Histdiagramm erstellen

Verfasst: Mittwoch 1. August 2012, 13:28
von misterbaldi
Hallo

ich bin in python nicht so auf trap...
so hoffe ich Ihr könnt mir helfen.

Ich möchte so einfach wie möglich aus meiner mysql db werte auslesen (Datum und Temperaturdaten)

Mein Mysql script funktioniert einmal wunderbar.

Code: Alles auswählen

# MySQLdbTest.py
# simple example of MySQLdb

import MySQLdb

# starting connection to database
conn = MySQLdb.connect ("10.59.240.203", "*****", "*****", "*****")

# getting the cursor
cursor = conn.cursor()

# setting the statement
cursor.execute ("Select * from metadata")

# get all rows
rows = cursor.fetchall ()

# print all rows
for row in rows:
	
	station = row[1]
	print station
# close cursor
cursor.close()

#close connection
conn.close()
So und in weiterer folge möchte ich mit matlot ein hist diagram erstellen jedoch habe ich keinen plan wie ich die
ausgelesenen daten dort einspiele :S (auf X achse das Datum und y Werte)

BSP CODE AUS MATLOT

Code: Alles auswählen

#!/usr/bin/env python
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

mu, sigma = 100, 15
x = mu + sigma*np.random.randn(10000)

# the histogram of the data
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75)

# add a 'best fit' line
y = mlab.normpdf( bins, mu, sigma)
l = plt.plot(bins, y, 'r--', linewidth=1)

plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)

plt.show()
Ich hoffe Ihr könnt mir helfen!
Falls es eine andere leichtere / unkompliziertere Methode gibt bin ich auch für diese offen es muss nicht unbedingt python sein.

MFG

Re: Python Histdiagramm erstellen

Verfasst: Mittwoch 1. August 2012, 13:34
von deets
Wie waere es, wenn du einfach mal aus beiden Skripten eines machst? Dann bist du doch schon so gut wie da. Natuelich musst du die eigentlichen zu plottenden Daten in eine Liste packen, da du nicht sagst, wie eine DB-Zeile aussieht & was daraus dargestellt werden soll kann man dazu nix sagen.