Skip to content
Advertisement

Automated cross stich pattern

I’m trying to create a cross stitch pattern with python as shown in the attached image.

So far I simply have the pixilated image. I could import it in excel and manually add the grid and colors etc. But how can I ‘easily’ automate this in python? Can I use any of the normal figure plotting functions (pyplot), or should I look into tkinter?

I’m fairly ok making scripts in python for engineering purposes, but completely new to GUI-stuff.

Ideally my output would be a vectored pdf

Cross stitch pattern

JavaScript
  • How do I set the gridlines at 0.5 rather than on the units (in the middle through each pixel)?

  • How do I plot text throught each pixel, I already have the image in an array with numbers how to plot this on top?

Advertisement

Answer

  • To shift the gridlines, you can simply change the ticks position:
    ax.set_xticks(np.arange(-0.5, arr.shape[1], 5))
    will put one major tick each 5 pixels starting from the border of the first pixel.
    ax.set_xticks(np.arange(-0.5, arr.shape[1], 1), minor=True)
    does the same thing but every pixel for minor ticks. And then do the same for y but with arr.shape[0].

  • To add text, you can simply use ax.text(x, y, 'text'). I used a dictionary to match the colors (in hex format because rgb lists cannot be dictionary keys) to the texts. What you need to pay attention to is that (i, j) matrix indexes correspond to (y, x) coordinates.

Here is the full code:

JavaScript

The image pixelated image gave me this result: result

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement