How to make thicker stem lines in matplolib

三世轮回 提交于 2021-01-27 21:42:06

问题


I want to make thicker stem lines in python when using plt.stem.

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 to set the linewidth in plt.stem?


回答1:


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()




回答2:


This can also be modified using plt.setp() as is shown in the matplotlib documentation example. The plt.setp() method allows you to set the properties of an artist object after it has been created.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.1, 2*np.pi, 10)
markerline, stemlines, baseline = plt.stem(x, np.cos(x), '-.')
plt.setp(stemlines, 'linewidth', 4)

plt.show()



来源:https://stackoverflow.com/questions/39292117/how-to-make-thicker-stem-lines-in-matplolib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!