2016-04-30 7 views
0

Ich zeichne zwei Zeilen: eine Reihe von experimentellen Datenpunkten und ein mathematisches Modell. Ich lasse die experimentellen Daten wie erwartet plotten, aber das mathematische Modell zeichnet keine Linie (nur das Symbol). Zusätzlich erhalte ich doppelte Legenden und obwohl ich einige der Vorschläge, die ich auf der Seite gesehen habe, ausprobiert habe, komme ich nicht zur Arbeit (wahrscheinlich führe ich sie nicht korrekt aus).Doppelte Beschriftungen und keine Linie im Plot in Python

import numpy as np 
from sympy import * 
from sympy import Matrix 
import matplotlib.pyplot as plt 

Stretch = [0.998122066, 1.0157277, 1.034507042, 1.052112676, 1.06971831, 1.088497653, 1.106103286, 1.12370892, 1.143661972, 1.160093897, 1.178873239, 1.196478873, 1.214084507, 1.23286385, 1.249295775, 1.266901408, 1.28685446, 1.303286385, 1.322065728, 1.339671362, 1.357276995, 1.374882629, 1.393661972, 1.411267606, 1.430046948, 1.447652582, 1.464084507, 1.48286385, 1.500469484, 1.518075117, 1.535680751, 1.554460094, 1.572065728, 1.59084507, 1.608450704, 1.626056338, 1.643661972, 1.661267606, 1.680046948, 1.697652582, 1.715258216, 1.734037559, 1.751643192, 1.770422535, 1.78685446, 1.805633803, 1.824413146, 1.844366197, 1.860798122, 1.878403756, 1.894835681, 1.912441315, 1.930046948, 1.948826291, 1.967605634, 1.985211268, 2.00399061, 2.021596244, 2.038028169, 2.057981221, 2.075586854, 2.092018779, 2.110798122, 2.128403756, 2.147183099, 2.165962441, 2.183568075, 2.201173709, 2.218779343, 2.237558685, 2.255164319, 2.272769953, 2.291549296, 2.307981221, 2.326760563, 2.344366197, 2.361971831, 2.380751174, 2.398356808, 2.415962441, 2.434741784, 2.452347418, 2.469953052, 2.488732394, 2.505164319] 
Stress = [0.010526316, 0.010549481, 0.01188998, 0.011913146, 0.012594206, 0.012618915, 0.013299975, 0.013323141, 0.014665184, 0.0153447, 0.016027304, 0.016708364, 0.017389424, 0.018729923, 0.018751544, 0.019432604, 0.019458858, 0.019480479, 0.020163084, 0.020844144, 0.020867309, 0.021548369, 0.022230974, 0.022254139, 0.022278849, 0.023617803, 0.024297319, 0.024979923, 0.025660983, 0.026999938, 0.027023104, 0.027705708, 0.029044663, 0.029069372, 0.030408327, 0.031747282, 0.033086237, 0.034425191, 0.035107796, 0.036446751, 0.037785705, 0.039784099, 0.041123054, 0.042463553, 0.044458858, 0.046457252, 0.048455646, 0.051113479, 0.053108784, 0.055763529, 0.059074623, 0.061729367, 0.065042006, 0.069014085, 0.072986163, 0.077614591, 0.081586669, 0.086872992, 0.092815666, 0.099420867, 0.106680875, 0.114597233, 0.123174574, 0.132408265, 0.142301396, 0.152852422, 0.164059797, 0.177240857, 0.191079812, 0.206236101, 0.22073295,  0.238519274, 0.256307141, 0.273434025, 0.293195577, 0.314929269, 0.335347171, 0.357740301, 0.382105572, 0.406470843, 0.434785026, 0.461123981, 0.488778725, 0.516435014, 0.544088213] 

c= [6.11739377e+00, 4.78409591e-04] 


plt.show() 
for o, d in zip (Stress, Stretch): 
    d1 = d2 = d 
    d3 = 1/(d1*d2) 
    d3 = 1/(d1*d2) 
    C11 = d1**2 
    C22 = d2**2 
    C33 = d3**2 
    p = 4*(c[1]/c[0])*(d3**(c[0]-2)) 
    S11 = -p/C11 + 4*C11*(c[1]/c[0])*(d1**(c[0]-2)) 
    S22 = -p/C22 + 4*C22*(c[1]/c[0])*(d2**(c[0]-2)) 
    T112 = (d1*S11)/(d2*d3) 
    T222 = (d2*S22)/(d1*d3) 
    plt.plot(d, T112, 'g--^', label = 'Model') 
    plt.plot(Stretch, Stress, 'b-o', label = 'Experimental') 
    plt.subplots_adjust(left=0.15) 
    plt.grid(True) 
    plt.ylabel('Stress') 
    plt.xlabel('Applied Stretch') 
    plt.title('Stress as a Function of Applied Stretch') 
plt.legend() 
plt.show() 

Antwort

0

plt.plot sollte nicht in einer Schleife über die einzelnen Daten aufgenommen werden, da es mit zwei Listen oder 2 arrays.As ein erster Schritt arbeiten, i 2 Listen für Ihre Modelldaten erstellt haben, dann war ich fähig, es zu zeichnen:

import matplotlib.pyplot as plt 

Stretch = [0.998122066, 1.0157277, 1.034507042, 1.052112676, 1.06971831, 1.088497653, 1.106103286, 1.12370892, 1.143661972, 1.160093897, 1.178873239, 1.196478873, 1.214084507, 1.23286385, 1.249295775, 1.266901408, 1.28685446, 1.303286385, 1.322065728, 1.339671362, 1.357276995, 1.374882629, 1.393661972, 1.411267606, 1.430046948, 1.447652582, 1.464084507, 1.48286385, 1.500469484, 1.518075117, 1.535680751, 1.554460094, 1.572065728, 1.59084507, 1.608450704, 1.626056338, 1.643661972, 1.661267606, 1.680046948, 1.697652582, 1.715258216, 1.734037559, 1.751643192, 1.770422535, 1.78685446, 1.805633803, 1.824413146, 1.844366197, 1.860798122, 1.878403756, 1.894835681, 1.912441315, 1.930046948, 1.948826291, 1.967605634, 1.985211268, 2.00399061, 2.021596244, 2.038028169, 2.057981221, 2.075586854, 2.092018779, 2.110798122, 2.128403756, 2.147183099, 2.165962441, 2.183568075, 2.201173709, 2.218779343, 2.237558685, 2.255164319, 2.272769953, 2.291549296, 2.307981221, 2.326760563, 2.344366197, 2.361971831, 2.380751174, 2.398356808, 2.415962441, 2.434741784, 2.452347418, 2.469953052, 2.488732394, 2.505164319] 
Stress = [0.010526316, 0.010549481, 0.01188998, 0.011913146, 0.012594206, 0.012618915, 0.013299975, 0.013323141, 0.014665184, 0.0153447, 0.016027304, 0.016708364, 0.017389424, 0.018729923, 0.018751544, 0.019432604, 0.019458858, 0.019480479, 0.020163084, 0.020844144, 0.020867309, 0.021548369, 0.022230974, 0.022254139, 0.022278849, 0.023617803, 0.024297319, 0.024979923, 0.025660983, 0.026999938, 0.027023104, 0.027705708, 0.029044663, 0.029069372, 0.030408327, 0.031747282, 0.033086237, 0.034425191, 0.035107796, 0.036446751, 0.037785705, 0.039784099, 0.041123054, 0.042463553, 0.044458858, 0.046457252, 0.048455646, 0.051113479, 0.053108784, 0.055763529, 0.059074623, 0.061729367, 0.065042006, 0.069014085, 0.072986163, 0.077614591, 0.081586669, 0.086872992, 0.092815666, 0.099420867, 0.106680875, 0.114597233, 0.123174574, 0.132408265, 0.142301396, 0.152852422, 0.164059797, 0.177240857, 0.191079812, 0.206236101, 0.22073295,  0.238519274, 0.256307141, 0.273434025, 0.293195577, 0.314929269, 0.335347171, 0.357740301, 0.382105572, 0.406470843, 0.434785026, 0.461123981, 0.488778725, 0.516435014, 0.544088213] 

c= [6.11739377e+00, 4.78409591e-04] 

Stretch_mod=[] 
Stress_mod=[] 

for o, d in zip (Stress, Stretch): 
    d1 = d2 = d 
    d3 = 1/(d1*d2) 
    d3 = 1/(d1*d2) 
    C11 = d1**2 
    C22 = d2**2 
    C33 = d3**2 
    p = 4*(c[1]/c[0])*(d3**(c[0]-2)) 
    S11 = -p/C11 + 4*C11*(c[1]/c[0])*(d1**(c[0]-2)) 
    S22 = -p/C22 + 4*C22*(c[1]/c[0])*(d2**(c[0]-2)) 
    T112 = (d1*S11)/(d2*d3) 
    T222 = (d2*S22)/(d1*d3) 
    Stretch_mod.append(d) 
    Stress_mod.append(T112) 

plt.plot(Stretch_mod, Stress_mod, 'g--^', label = 'Model')   
plt.plot(Stretch, Stress, 'b-o', label = 'Experimental')  
plt.subplots_adjust(left=0.15)     
plt.grid(True)       
plt.ylabel('Stress')       
plt.xlabel('Applied Stretch')     
plt.title('Stress as a Function of Applied Stretch')   
plt.legend() 
plt.show()