2016-11-30 12 views
0

Ich versuche, ein einfaches Streudiagramm zu erstellen. Für diesen speziellen Zweck möchte ich konzentrische Kreise um den Ursprung mit verschiedenen Farben (wie ein Bullseye mit 3 Regionen). Ich frage mich, ob es etwas Ähnliches wie axvspan und axhspan aber für konzentrische Schattierung gibt?Matplotlib konzentrische Schattierung (Bullseye) im Streudiagramm?

Lassen Sie mich Ihnen ein Beispiel geben:

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 

x = x = np.linspace(0, 20, 50) 
y = np.cos(3*x) 


a = 3  # radius 0 to >a 
b = 5  # radius a to >b  
c = 7  # radius b to c 

plt.axvspan(a, b, color='r', alpha = 0.5) 
plt.axhspan(a, b, color='y', alpha = 0.5) 
plt.scatter(x, y) 
plt.show() 

Anstelle der horizontalen und vertikalen Schattierung, ich will konzentrische grüne Schattierung mit einem Radius a vom Ursprung, gelb a-b und rot von b zu c. Irgendwelche Ideen?

+0

versuchen mit meiner Lösung – eyllanesc

Antwort

1

Dies ist meine Lösung:

import numpy as np 
import matplotlib.pyplot as plt 

fig, ax = plt.subplots() 

x = np.linspace(0, 20, 50) 
y = np.cos(3*x) 

a = 3  # radius 0 to >a 
b = 5  # radius a to >b 
c = 7  # radius b to c 


circle1 = plt.Circle((0, 0), a, color='green', alpha=0.3) 
circle2 = plt.Circle((0, 0), b, color='yellow', alpha=0.3) 
circle3 = plt.Circle((0, 0), c, color='red', alpha=0.3) 

ax.add_artist(circle3) 
ax.add_artist(circle2) 
ax.add_artist(circle1) 

plt.scatter(x, y) 
plt.axis([-22, 22, -22, 22]) 

plt.show() 

Ausgang:

enter image description here

+0

Große Lösung! Vielen Dank! Wie kann ich entscheiden, die Streuung über die Kreise zu zeichnen? Plus: Kann man auch Ellipsen verwenden? – Rachel

+0

@Rachel Wenn ich Ihnen meine Antwort gegeben habe, markieren Sie sie als richtig. – eyllanesc

+0

Entschuldigung. Es tat jetzt. Obwohl ich nicht glaube, dass die Lösung völlig korrekt ist, da die Kreise über der Streuung sind - und das ist kein Bullseye-Chart. – Rachel

Verwandte Themen