Export png file with line width of 1 pixel

Hi,

I want to export .png file that contains a line with a width of one pixel.

The best I could come up with so far is:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(figsize=(3, 3), facecolor='#000000')
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim(-3, 3)
ax.set_ylim(-3, 3)
ax.set_aspect("equal", adjustable="box")
ax.axis('off')
fig.tight_layout(pad=0)
DPI = 100

x = np.arange(-3, 10*np.pi, 0.1) # start,stop,step
y = np.sin(x)
plt.plot(x,y, linewidth=72/fig.dpi/2, snap=True, antialiased=False)
fig.savefig("test.png", dpi=fig.dpi,)

However, there are still parts of the line that have a width of two (marked box is 4 pixels)…

I rather want a behavior such as for cv2.line().

I don’t think that is possible with our drawing engine. We use Agg to render png files, and it is not particularly suited to poking pixels. If you want to set a matrix to on/off, you could do so manually and then use imshow instead of plot.