Quantcast
Channel: Uncategorized - Matplotlib
Viewing all articles
Browse latest Browse all 50

Export png file with line width of 1 pixel

$
0
0

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().

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 50

Trending Articles