Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib change line width on existing skimage plot

I am using the plotting function that is encapsulated in skimage to draw matches between two sets of keypoints. In particular, I am using this function: plot_matches

This works fine but the lines that are drawn are quite thick. I know with matplotlib one can control the line thickness with the linewidth parameter in the plot. In this case, the plot function is called by the plot_matches function in the link.

The way, I am using it as follows:

import matplotlib.pyplot as plt
from skimage.feature import plot_matches

fig, ax = plt.subplots()
plt.gray()
plot_matches(ax, img1, img2, k1[:, [0, 1]],
             k2[:, [0, 1]], matches, only_matches=True)
ax.axis('off')
plt.show()

Is there a way to control the linewidth property in this kind of usage?

like image 363
Luca Avatar asked Jan 24 '26 09:01

Luca


2 Answers

Another possible solution would be to get a list of the line2D objects and then change the linewidths using set_linewidth()

lines = ax.lines
for line in lines:

    line.set_linewidth(2)
like image 54
DavidG Avatar answered Jan 25 '26 21:01

DavidG


Unfortunately the plot_matches just hardcodes the plot parameters according to its internal settings and no further keyword arguments are passed onto the matplotlib function.

An option you have is to use th rcParams to change the standard linewidth before calling that function.

plt.rcParams["lines.linewidth"] = 3
plot_matches(...)

Possibly you need to set it back to the default (1.5) after the plot to be able to use the standard in further plots to be produced.

like image 22
ImportanceOfBeingErnest Avatar answered Jan 25 '26 23:01

ImportanceOfBeingErnest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!