Ich versuche, ein ziemlich einfaches Streudiagramm mit Fehlerbalken und Semilogie zu erstellen. Was ein bisschen anders ist als Tutorials, die ich gefunden habe, ist, dass die Farbe des Streudiagramms eine andere Menge verfolgen sollte. Auf der einen Seite konnte ich ein Streudiagramm mit den Fehlerbalken mit meinen Daten erstellen, aber nur mit einer Farbe. Auf der anderen Seite realisierte ich ein Streudiagramm mit den richtigen Farben, aber ohne die Fehlerbalken. Ich bin nicht in der Lage, die zwei verschiedenen Dinge zu kombinieren.Python-Streudiagramm mit Fehlerbalken und Farben, die eine physikalische Größe darstellen
Hier ist ein Beispiel gefälschte Daten mit:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
n=100
Lx_gas = 1e40*np.random.random(n) + 1e37
Tx_gas = np.random.random(n) + 0.5
Lx_plus_error = Lx_gas
Tx_plus_error = Tx_gas/2.
Tx_minus_error = Tx_gas/4.
#actually positive numbers, this is the quantity that should be traced by the
#color, in this example I use random numbers
Lambda = np.random.random(n)
#this is actually different from zero, but I want to be sure that this simple
#code works with the log axis
Lx_minus_error = np.zeros_like(Lx_gas)
#normalize the color, to be between 0 and 1
colors = np.asarray(Lambda)
colors -= colors.min()
colors *= (1./colors.max())
#build the error arrays
Lx_error = [Lx_minus_error, Lx_plus_error]
Tx_error = [Tx_minus_error, Tx_plus_error]
##--------------
##important part of the script
##this works, but all the dots are of the same color
#plt.errorbar(Tx_gas, Lx_gas, xerr = Tx_error,yerr = Lx_error,fmt='o')
##this is what is should be in terms of colors, but it is without the error bars
#plt.scatter(Tx_gas, Lx_gas, marker='s', c=colors)
##what I tried (and failed)
plt.errorbar(Tx_gas, Lx_gas, xerr = Tx_error,yerr = Lx_error,\
color=colors, fmt='o')
ax = plt.gca()
ax.set_yscale('log')
plt.show()
Ich habe sogar versucht die Scatterplot nach dem errorbar zu plotten, aber aus irgendeinem Grund alles auf dem gleichen Fenster aufgetragen ist im Hintergrund in Bezug auf die errorplot setzen. Irgendwelche Ideen?
Danke!
Dies ist, was ich gesucht habe! – andrea