Removing Horizontal Lines in image (OpenCV, Python, Matplotlib)

Obtain binary image. Load the image, convert to grayscale, then Otsu’s threshold to obtain a binary black/white image. Detect and remove horizontal lines. To detect horizontal lines, we create a special horizontal kernel and morph open to detect horizontal contours. From here we find contours on the mask and “fill in” the detected horizontal contours … Read more

Matplotlib figure facecolor (background color)

It’s because savefig overrides the facecolor for the background of the figure. (This is deliberate, actually… The assumption is that you’d probably want to control the background color of the saved figure with the facecolor kwarg to savefig. It’s a confusing and inconsistent default, though!) The easiest workaround is just to do fig.savefig(‘whatever.png’, facecolor=fig.get_facecolor(), edgecolor=”none”) … Read more

Matplotlib: Plotting numerous disconnected line segments with different colors

use LineCollection: import numpy as np import pylab as pl from matplotlib import collections as mc lines = [[(0, 1), (1, 1)], [(2, 3), (3, 3)], [(1, 2), (1, 3)]] c = np.array([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)]) lc = mc.LineCollection(lines, colors=c, linewidths=2) fig, ax = pl.subplots() ax.add_collection(lc) ax.autoscale() … Read more

Matplotlib connect scatterplot points with line – Python

I think @Evert has the right answer: plt.scatter(dates,values) plt.plot(dates, values) plt.show() Which is pretty much the same as plt.plot(dates, values, ‘-o’) plt.show() You can replace -o with another suitable format string as described in the documentation. You can also split the choices of line and marker styles using the linestyle= and marker= keyword arguments.

Text box with line wrapping in matplotlib?

The contents of this answer were merged into mpl master in https://github.com/matplotlib/matplotlib/pull/4342 and will be in the next feature release. Wow… This is a thorny problem… (And it exposes a lot of limitations in matplotlib’s text rendering…) This should (i.m.o.) be something that matplotlib has built-in, but it doesn’t. There have been a few threads … Read more

matplotlib: Group boxplots

How about using colors to differentiate between “apples” and “oranges” and spacing to separate “A”, “B” and “C”? Something like this: from pylab import plot, show, savefig, xlim, figure, \ hold, ylim, legend, boxplot, setp, axes # function for setting the colors of the box plots pairs def setBoxColors(bp): setp(bp[‘boxes’][0], color=”blue”) setp(bp[‘caps’][0], color=”blue”) setp(bp[‘caps’][1], color=”blue”) … Read more

How to pick a new color for each plotted line within a figure in matplotlib?

I usually use the second one of these: from matplotlib.pyplot import cm import numpy as np #variable n below should be number of curves to plot #version 1: color = cm.rainbow(np.linspace(0, 1, n)) for i, c in zip(range(n), color): plt.plot(x, y, c=c) #or version 2: color = iter(cm.rainbow(np.linspace(0, 1, n))) for i in range(n): c … Read more