So I'm trying to expand on this code, which is the only code I could find to display Markov Chains as a diagram of nodes and arrows. Specifically, I needed it to work for more than 4 states and I have been editing it to suit my needs. Since right now I want to use it for n=7 where any two states have a transition probability, it can get very messy with all the arrows, which is why I wanted to use the parameter alpha in the matplotlib.patches.FancyArrow() function.
However, I have tested it and while I get an error if I give it a value outside of the interval [0,1], any value in that interval seems to do nothing, whether it's 0.001 or 0.999. The documentation isn't great, it includes alpha as a possible kwarg but the description just says "unknown". In the "Arrow Guide" there is no mention of this parameter at all. So does anyone know how I can make my arrows more transparent?
Here is a code example where you can change alpha and see no change:
import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(20,20))
plt.xlim(-10,10)
plt.ylim(-10,10)
coords = [(5,7),(3,-6),(0,5),(-2,-4)]
for (x,y) in coords:
arrow = mpatches.FancyArrow(0,0,x,y,
width = .2,
head_width = 1,
length_includes_head = True,
alpha = 0.1)
p = PatchCollection(
[arrow],
edgecolor = '#a3a3a3',
facecolor = '#a3a3a3'
)
ax.add_collection(p)
plt.axis("off")
plt.show()
CodePudding user response:
Ok I just realized my mistake (well sort of, I don't really understand the mechanics of why this works). I have to pass the alpha keyword in the PatchCollection() function. Then it works. Thank you to myself for figuring this out lol