Does anyone know how to make the linewidth of a single line change as a function of x in matplotlib? For example, how would you make a line thin for small values of x, and thick for large values of x?
The linewidth and linestyle property can be used to change the width and the style of the line chart. Linewidth is specified in pixels.
Click On chart, then you will see a Values filled and category groups Box on right side of graph, then in Values filled, right-click on any values Go to "Series Properties" --> "Border " -- > "Line Width" and then set the size.
Basically, you need to use a polygon instead of a line. As a quick 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()
Or if you want 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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With