연평도꽃게잡이 연평도꽃게잡이 - 1 year ago 93
Python Question

How to make thicker stem in python

I want to make a thicker line stem in python

here is my code

import matplotlib.pyplot as plt
import numpy as np

N = 20

n = np.arange(0, 2*N, 1)

x = np.exp(-n/N)*np.exp(1j * 2*np.pi/N*n)

plt.stem(n,x.real)

plt.show()


I changed
'plt.stem(n,x.real,linewidth=10)'
. but, nothing changed

is there no function about
linewidth
in
plt.stem
?

Answer Source

The documentation of plt.stem shows that the function returns all the line objects created by the plot. You can use that to manually make the lines thicker after plotting:

import matplotlib.pyplot as plt
import numpy as np

N = 20
n = np.arange(0, 2*N, 1)
x = np.exp(-n/N)*np.exp(1j * 2*np.pi/N*n)

markers,stems,base = plt.stem(n,x.real) 
for stem in stems:
    stem.set_linewidth(10)
plt.show()

result