How do you change the line width of one line depending on x in matplotlib?

Does anyone know how to change the line width of one line depending on x in matplotlib? For example, how would you make a thin line for small x values ​​and a thickness for large x values?

+6
source share
1 answer

Basically, you need to use a polygon instead of a string. As a short example:

import numpy as np import matplotlib.pyplot as plt # Make the original line... x = np.linspace(0, 10, 100) y = 2 * x thickness = 0.5 * np.abs(np.sin(x) * np.cos(x)) plt.fill_between(x, y - thickness, y + thickness, color='blue') plt.show() 

enter image description here

Or, if you need something closer to your description:

 import numpy as np import matplotlib.pyplot as plt # Make the original line... x = np.linspace(0, 10, 100) y = np.cos(x) thickness = 0.01 * x plt.fill_between(x, y - thickness, y + thickness, color='blue') plt.show() 

enter image description here

+8
source

Source: https://habr.com/ru/post/901734/


All Articles