Seite 1 von 1

matplotlib

Verfasst: Mittwoch 30. März 2011, 22:24
von mit
Hi,
Ist moeglich die Abstaende an der x Achse zu aendern damit die Werte nicht so eng beieinander legen?

Code: Alles auswählen

from pylab import *
import matplotlib.pyplot as plt

y1 = [20, 24, 8, 4, 12, 22, 31, 25, 15, 28, 12, 27, 22, 22, 27, 14, 32, 28, 8, 17, 2, 8, 29, 13, 14, 20, 11, 28, 8]
y2= [2, 32, 28, 1, 22, 11, 14, 27, 3, 31, 12, 20, 32, 24, 24, 16, 7, 10, 12, 11, 3, 32, 10, 20, 14, 14, 3, 25, 14]


#fig = plt.figure(figsize=(40,40))
fig = plt.figure()
ax = fig.add_subplot(111)

ax.set_title('The red point should be on the path')
ax.grid(True)

maxy = max(max(y1), max(y2))
maxx = max(len(y1), len(y2))
x = range(1,maxx+1)

plt.plot(x, y1, '--bo', x, y2, '--go')

# rotates and right aligns the x labels, and moves the bottom of the
# axes up to make room for them
fig.autofmt_xdate()


# set x and y labels
plt.xticks(range(1, maxx+2, 1))

#ax.set_xticks(4.5)
plt.yticks(range(1, maxy+1, 1))

plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.legend(('Model length', 'Data length'),
          'best', shadow=True, fancybox=True)

for i, label in enumerate(y1):
  plt.text (x[i], y1[i]+0.2, label,
            horizontalalignment='center', fontsize=8 )

for i, label in enumerate(y2):
  plt.text (x[i], y2[i]+0.2, label,
            horizontalalignment='center', fontsize=8 )

plt.savefig('test.png')


Vielen Dank im Vorraus.

Re: matplotlib

Verfasst: Donnerstag 31. März 2011, 10:58
von gkuhl
@mit: Die kurze Antwort ist "Nein". Was du aber stattdessen ändern könntest:
  • Die Länge der Achse vergrößern.
  • Weniger Werte anzeigen, z.B. nur jeden zweiten.
  • Die Schriftgröße verkleinern.
Grüße
Gerrit

Re: matplotlib

Verfasst: Donnerstag 31. März 2011, 13:51
von Drache
Hilft dir das hier weiter ?

Code: Alles auswählen

fig.subplots_adjust(left=0.05, bottom=0.10, right=0.95, top=0.9,wspace=0.0, hspace=0.0)
eventuell noch

Code: Alles auswählen

plt.rcParams.update({'figure.figsize': [12,4]})
Machs gut
Drache

Re: matplotlib

Verfasst: Dienstag 9. August 2011, 12:57
von Campionissimo
@gkuhl

Wie kann ich die Achse skalieren, dass nur jeder zweite oder dritte Wert angezeigt wird.
Oder autoscale sodas die Beschriftung nicht übereinander ist.

Code: Alles auswählen

xListA[]
wird so gemacht
dates = map(datetime.strptime, parts[3].split(), ["%H%M%S"] )
xList.append((dates))

fig1 = plt.figure(dpi=200)
ax1 = fig1.add_subplot(111)
ax1.plot_date((xListA),(yListA),"b-")
ax1.xaxis.set_major_formatter(DateFormatter('%H:%M'))
hab jetzt schon länger gesucht und nicht wirklich was gefunden.
Danke

Re: matplotlib

Verfasst: Dienstag 9. August 2011, 15:27
von gkuhl
@Campionissimo: Du kannst die Beschriftung mit matplotlib.pyplot.xticks anpassen. Damit ist es auch möglich den Text zu rotieren, Schriftgröße zu ändern, etc.

Grüße
Gerrit

Re: matplotlib

Verfasst: Mittwoch 10. August 2011, 09:16
von Campionissimo
Danke erstmal.
+
Ich hab es mit

labels = ax1.get_xticklabels()
setp(labels, rotation=30, fontsize=10)

gemacht ist besser. Aber noch besser wäre es wenn ich nur 10 Werte benutzen würd, aber es ist ein Datumsformat.
Wollte es so probieren, aber leider falsch
pylab.xticks(pylab.arange(10))

Gruß