2017-10-13 2 views
0

ich die folgenden Codes bin mit mehreren Datenpunkten plotten (xi, yi)matplotlib: legte zwei xy-Plots in einem

import numpy as np 
import matplotlib.pyplot as plt 

xi = np.array(data_df[['col_A']]) 
yi = np.array(data_df[['col_B']]) 

plt.figure() 
plt.plot(xi, yi) 

x = np.linspace(0, 30, 30) 
y= np.exp(x*0.16) 
plt.plot(x, y) 
plt.show() 

enter image description here

Ich möchte die Handlung wie folgt aussehen:

enter image description here

Vielen Dank!

+0

Der Code aus der Frage erzeugt die zwei Diagramme in einer einzigen Achse. Es ist also ziemlich nutzlos, nach etwas zu fragen, das schon da ist. – ImportanceOfBeingErnest

Antwort

1

Benutzerunterplots, um mehr als 1 Diagramme in einer Abbildung zu plotten. Sie müssen plt.show() nur einmal aufrufen.

import numpy as np 
import matplotlib.pyplot as plt 

xi = np.array(data_df[['col_A']]) 
yi = np.array(data_df[['col_B']]) 

plt.figure() 
plt.subplot(2,1,1) 
plt.plot(xi, yi) 

plt.subplot(2,1,2) 
x = np.linspace(0, 30, 30) 
y= np.exp(x*0.16) 
plt.plot(x, y) 
plt.show() 
+0

Ich meine, ich will nur eine Handlung in einer Figur. Aber das ONE-Plot muss sowohl die (xi, yi) als auch die angepassten Kurven haben. – Edamame

+2

Kool dann nicht plt.show() 2 mal aufrufen. Nennen Sie es, sobald alle Figuren endlich gemalt sind. –

+0

Danke. Dann für (xi, yi), wie zeichne ich einfach "Punkte" anstatt sie zu verbinden? – Edamame

Verwandte Themen