-2
$\begingroup$

Question

Please show me Python programming codes that shows graphs using the list method.

Moreover, I want to know how to change graph lines to "-" or "*".

Thank you for your answer in advance.

%matplotlib inline 

import decimal 
import numpy as np
import matplotlib.pyplot as plt

decimal.getcontext().prec = 10
r=0.005
D0=12000000
HC=100000

x=0
y=0

for i  in range(100):
    D= D0*(1-r)**i - HC*(1-(1-r)**i)/r  
    x=i
    y=D
    print("D["+str(i)+"] ="+"{:,f}".format(D))
    print("D["+str(i)+"] ="+"{:,.1f}".format(round(D,0)))
    plt.plot(x, y, marker="*",color = "red", linestyle = "--")

plt.show()
$\endgroup$
0
$\begingroup$

Partially, I solved by myself.


%matplotlib inline
import decimal
import matplotlib.pyplot as plt

decimal.getcontext().prec = 10
r=0.005
D0=12000000
HC=100000

x=0
y=0

X=[];
Y=[];

for i  in range(100):
    D= D0*(1-r)**i - HC*(1-(1-r)**i)/r  
    x=i
    y=D
    X.append(x)
    Y.append(y)
#    print("D["+str(i)+"] ="+"{:,.1f}".format(round(D,0)))

plt.grid(True)
plt.plot(X, Y, color = "b")
#plt.show()
plt.savefig('./Graph.png')
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.