I am plotting two similar trajectories in matplotlib and I'd like to plot each of the lines with partial transparency so that the red (plotted second) doesn't obscure the blue.
EDIT: Here's the image with transparent lines.
Make lines, i.e., line1 and line2, using plot() method. To hide the lines, use line. remove() method.
To set transparency for bars in a Bar Plot using Matplotlib PyPlot API, call matplotlib. pyplot. bar() function, and pass required alpha value to alpha parameter of bar() function. Of course, there are other named parameters, but for simplicity, only alpha parameter is given along with required x and height .
You can update the alpha value of an existing Line2D , using the set_alpha method. The idea would be to plot the line once and then update the alpha in the loop.
Inmatplotlib, the plots have a parameter, alpha= to change transparency.
Plain and simple:
plt.plot(x, y, 'r-', alpha=0.7)
(I know I add nothing new, but the straightforward answer should be visible).
After I plotted all the lines, I was able to set the transparency of all of them as follows:
for l in fig_field.gca().lines:
l.set_alpha(.7)
EDIT: please see Joe's answer in the comments.
It really depends on what functions you're using to plot the lines, but try see if the on you're using takes an alpha value and set it to something like 0.5. If that doesn't work, try get the line objects and set their alpha values directly.
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