Generate Matlab plot markers

5

Matlab has a useful command for visualizing data: plot. It draws data points using "markers" in 2-D space, connecting them with lines; however, for this challenge, let's ignore the lines and use only markers. In fact, only one marker.

Input: one of Matlab's marker symbols: . o x + * s d v ^ < > p h

Output: corresponding image for that marker, which is one of the following 13 icons: markers

To make it clearer, here are the same icons enlarged, so the pixels can be easily seen:

markers x5

  • Take the input as a string, a char, an integer ASCII code, or anything equivalent

  • Produce the output by displaying the image, returning it as a function's return value, saving it to a file, etc

  • The image should have pixels of two different colours in it. I used blue on white, because this is what Matlab uses by default, but any other colour scheme is OK, e.g. white on black.

  • The image can have padding of background colour of any size

  • The pixels can be enlarged by any integer ratio, e.g. instead of the original 11-by-9 image for the triangle, you can output a 110-by-72 image, in which 10-by-8 blocks represent the original pixels

    • As a corollary of the above, you can output text with glyphs like instead of an image, if you can print this text properly (i.e. without gaps between glyphs) on the same system which runs the code

For quick reference, here are the bitmaps for each input:

  • .

    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 1 1 1 0 0 0 0
    0 0 0 1 1 1 1 1 0 0 0
    0 0 0 0 1 1 1 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    
  • o

    0 0 0 0 1 1 1 0 0 0 0
    0 0 1 1 0 0 0 1 1 0 0
    0 0 1 0 0 0 0 0 1 0 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 0 1 0 0 0 0 0 1 0 0
    0 0 1 1 0 0 0 1 1 0 0
    0 0 0 0 1 1 1 0 0 0 0
    
  • x

    0 0 1 0 0 0 0 0 1 0 0
    0 0 0 1 0 0 0 1 0 0 0
    0 0 0 0 1 0 1 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 1 0 1 0 0 0 0
    0 0 0 1 0 0 0 1 0 0 0
    0 0 1 0 0 0 0 0 1 0 0
    
  • +

    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    0 1 1 1 1 1 1 1 1 1 0
    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    
  • *

    0 0 0 0 0 1 0 0 0 0 0
    0 0 1 0 0 1 0 0 1 0 0
    0 0 0 1 0 1 0 1 0 0 0
    0 0 0 0 1 1 1 0 0 0 0
    0 1 1 1 1 1 1 1 1 1 0
    0 0 0 0 1 1 1 0 0 0 0
    0 0 0 1 0 1 0 1 0 0 0
    0 0 1 0 0 1 0 0 1 0 0
    0 0 0 0 0 1 0 0 0 0 0
    
  • s

    0 1 1 1 1 1 1 1 1 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 1 1 1 1 1 1 1 1 0
    
  • d

    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 1 0 1 0 0 0 0
    0 0 0 1 0 0 0 1 0 0 0
    0 0 0 1 0 0 0 1 0 0 0
    0 0 1 0 0 0 0 0 1 0 0
    0 1 0 0 0 0 0 0 0 1 0
    0 0 1 0 0 0 0 0 1 0 0
    0 0 0 1 0 0 0 1 0 0 0
    0 0 0 1 0 0 0 1 0 0 0
    0 0 0 0 1 0 1 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    
  • v

    1 1 1 1 1 1 1 1 1 1 1
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    0 0 1 0 0 0 0 0 1 0 0
    0 0 1 0 0 0 0 1 0 0 0
    0 0 0 1 0 0 0 1 0 0 0
    0 0 0 0 1 0 1 0 0 0 0
    0 0 0 0 1 0 1 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    
  • ^

    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 1 0 1 0 0 0 0
    0 0 0 0 1 0 1 0 0 0 0
    0 0 0 1 0 0 0 1 0 0 0
    0 0 1 0 0 0 0 1 0 0 0
    0 0 1 0 0 0 0 0 1 0 0
    0 1 0 0 0 0 0 0 0 1 0
    0 1 0 0 0 0 0 0 0 1 0
    1 1 1 1 1 1 1 1 1 1 1
    
  • <

    0 0 0 0 0 0 0 0 1 0 0
    0 0 0 0 0 0 1 1 1 0 0
    0 0 0 0 1 1 0 0 1 0 0
    0 0 0 1 0 0 0 0 1 0 0
    0 1 1 0 0 0 0 0 1 0 0
    1 0 0 0 0 0 0 0 1 0 0
    0 1 1 0 0 0 0 0 1 0 0
    0 0 0 1 1 0 0 0 1 0 0
    0 0 0 0 0 1 0 0 1 0 0
    0 0 0 0 0 0 1 1 1 0 0
    0 0 0 0 0 0 0 0 1 0 0
    
  • >

    0 0 1 0 0 0 0 0 0 0 0
    0 0 1 1 1 0 0 0 0 0 0
    0 0 1 0 0 1 1 0 0 0 0
    0 0 1 0 0 0 0 1 0 0 0
    0 0 1 0 0 0 0 0 1 1 0
    0 0 1 0 0 0 0 0 0 0 1
    0 0 1 0 0 0 0 0 1 1 0
    0 0 1 0 0 0 1 1 0 0 0
    0 0 1 0 0 1 0 0 0 0 0
    0 0 1 1 1 0 0 0 0 0 0
    0 0 1 0 0 0 0 0 0 0 0
    
  • p

    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 1 1 0 0 0 0 0
    0 1 1 1 1 1 1 1 1 0 0
    0 0 1 0 0 0 0 1 0 0 0
    0 0 0 1 0 0 1 0 0 0 0
    0 0 0 1 0 1 1 0 0 0 0
    0 0 1 1 1 0 1 1 0 0 0
    0 0 1 0 0 0 0 1 0 0 0
    
  • h

    0 0 0 0 0 1 0 0 0 0 0
    0 0 0 0 1 1 0 0 0 0 0
    0 0 1 1 1 0 1 1 1 0 0
    0 0 1 0 0 0 0 1 0 0 0
    0 0 0 1 0 0 0 1 0 0 0
    0 0 1 0 0 0 0 1 0 0 0
    0 0 1 1 1 0 1 1 1 0 0
    0 0 0 0 1 1 0 0 0 0 0
    0 0 0 0 0 1 0 0 0 0 0
    

Any padding with zeros which exists in these bitmaps is optional. So e.g. for the . input, a 5x5 image would be sufficient.

anatolyg

Posted 2018-11-11T19:50:50.373

Reputation: 10 719

Possibly add [tag:compression]? – Jonathan Frech – 2018-11-11T20:27:58.983

Can output be unpad? (5*5 for .) – l4m2 – 2018-11-12T00:29:58.680

Yes. Thought it would be obvious; will clarify. – anatolyg – 2018-11-12T00:31:49.160

2Why is the star so horribly mutilated? ergh – Jo King – 2018-11-12T00:55:51.780

1I am more fascinated by the fact that it's still recognizable when the pixels are small enough! – anatolyg – 2018-11-12T01:00:05.633

1

@JonathanFrech Rather than compression, I think [tag:kolmogorov-complexity] is more appropriate due to the limited number of potential inputs and direct mapping of inputs to outputs (similar to this challenge).

– None – 2018-11-13T15:00:25.310

@Rogem I agree that [tag:kolmogorov-complexity] could fit, however such challenges generally are about constant output and only seldom allow input of any kind. Therefore I suggested [tag:compression]. – Jonathan Frech – 2018-11-13T22:18:21.697

Answers

2

Node.js, 310 bytes

Takes the ASCII code of the symbol as input.

n=>Buffer(`~A<<13)$$"~"6+'?'+6"~'81<<<18'~/973202459/~"$$)31<<A~"%;3)3;%"~~ !&(=@=-#! ~""""?""""~"%>3*,:3~~"$))1<1))$"~"'.'"~?<<<<<<<?~1)$"$)1`.split`~`[n*7%86%17]).map(c=>s+=(g=n=>n--?' █'[[...Buffer('$8$$L0$,4$(8(4T(!#""0($,|T8$F'),290,280,34,38,1051].map(c=>p+=c-32,p=0)[c-32]>>n&1]+g(n):`
`)(11),s='')&&s

Try it online!

How?

All symbols can be generated by combining \$34\$ distinct binary patterns.

Each pattern is identified with a character \$C\$ (from space to "A").

The patterns are ordered from lowest to highest, using their decimal representation \$N\$. What's actually stored is the difference \$d\$ between two consecutive patterns, plus \$32\$.

 ID |  C  | pattern     |    N |    d | d+32
----+-----+-------------+------+------+------
  0 | ` ` | 00000000100 |    4 |    4 |   36
  1 | `!` | 00000011100 |   28 |   24 |   56
  2 | `"` | 00000100000 |   32 |    4 |   36
  3 | `#` | 00000100100 |   36 |    4 |   36
  4 | `$` | 00001010000 |   80 |   44 |   76
  5 | `%` | 00001100000 |   96 |   16 |   48
  6 | `&` | 00001100100 |  100 |    4 |   36
  7 | `'` | 00001110000 |  112 |   12 |   44
  8 | `(` | 00010000100 |  132 |   20 |   52
  9 | `)` | 00010001000 |  136 |    4 |   36
 10 | `*` | 00010010000 |  144 |    8 |   40
 11 | `+` | 00010101000 |  168 |   24 |   56
 12 | `,` | 00010110000 |  176 |    8 |   40
 13 | `-` | 00011000100 |  196 |   20 |   52
 14 | `.` | 00011111000 |  248 |   52 |   84
 15 | `/` | 00100000000 |  256 |    8 |   40
 16 | `0` | 00100000001 |  257 |    1 |   33
 17 | `1` | 00100000100 |  260 |    3 |   35
 18 | `2` | 00100000110 |  262 |    2 |   34
 19 | `3` | 00100001000 |  264 |    2 |   34
 20 | `4` | 00100011000 |  280 |   16 |   48
 21 | `5` | 00100100000 |  288 |    8 |   40
 22 | `6` | 00100100100 |  292 |    4 |   36
 23 | `7` | 00100110000 |  304 |   12 |   44
 24 | `8` | 00110001100 |  396 |   92 |  124
 25 | `9` | 00111000000 |  448 |   52 |   84
 26 | `:` | 00111011000 |  472 |   24 |   56
 27 | `;` | 00111011100 |  476 |    4 |   36
 28 | `<` | 01000000010 |  514 |   38 |   70
 29 | `=` | 01100000100 |  772 |  258 |  290
 30 | `>` | 01111111100 | 1020 |  248 |  280
 31 | `?` | 01111111110 | 1022 |    2 |   34
 32 | `@` | 10000000100 | 1028 |    6 |   38
 33 | `A` | 11111111111 | 2047 | 1019 | 1051

The 29 first values \$d+32\$ can be directly converted to ASCII characters and stored as a Buffer. The last 5 ones are stored as number literals.

[...Buffer('$8$$L0$,4$(8(4T(!#""0($,|T8$F'),290,280,34,38,1051]

Using the characters \$C\$ defined above, we can encode each symbol as a string.

Example:

..█........     00100000000 --> '/'
..███......     00111000000 --> '9'
..█..██....     00100110000 --> '7'
..█....█...     00100001000 --> '3'
..█.....██.     00100000110 --> '2'
..█.......█ --> 00100000001 --> '0' --> '/973202459/'
..█.....██.     00100000110 --> '2'
..█...██...     00100011000 --> '4'
..█..█.....     00100100000 --> '5'
..███......     00111000000 --> '9'
..█........     00100000000 --> '/'

All symbols are stored in a single string, delimited with ~. We use a hash function to convert the input ASCII code into the position of the symbol in the list.

Arnauld

Posted 2018-11-11T19:50:50.373

Reputation: 111 334

2

Charcoal, 163 154 152 bytes

≔█η≡θo«G→↘→²η‖O↘¬»d«G↘³↓²↘³η‖O¬»h«GH↖↑→→↑↗↓↘→→↙↓²η‖O↓».GX³ηpG↑²↙⁴↖²→⁸↙³↓³→²↓²↖³↙²←³↓²↗²↑³ηsB⁹η¿№x+*θ«F¬⁼θ+PX×⁴ηF¬⁼θxP+×⁵η»«GH←←←←←↘↓↘↓↘↘↓↘²η‖O⟲⊗⌕v>^<θ

Try it online! Link is to verbose version of code. Explanation:

≔█η

Get the character into a variable. As @ASCII-only explains, a properly encoded Charcoal file would use three bytes to express this character, so it needs to be in a variable as it gets used a lot. (But it's still 2 bytes shorter than the previous approach.)

≡θ

Use a switch statement for the six easy characters.

o«G→↘→²η‖O↘¬»

Handle the o by drawing one eighth of the figure and mirroring it three times.

d«G↘³↓²↘³η‖O¬»

Handle the d by drawing one quarter of the figure and mirroring it twice.

h«GH↖↑→→↑↗↓↘→→↙↓²η‖O↓»

Handle the h by drawing the top half and mirroring it.

.GX³η

Handle the . by drawing a diamond.

pG↑²↙⁴↖²→⁸↙³↓³→²↓²↖³↙²←³↓²↗²↑³η

Handle the p by drawing it manually.

sB⁹η

Handle the s by drawing a hollow rectangle. (This one is the last of the six because Box can take 3 parameters but the following ¿ isn't legal as a parameter.)

¿№x+*θ«F¬⁼θ+PX×⁴ηF¬⁼θxP+×⁵η»

Handle the x, + and *, the latter by overlapping the former.

«GH←←←←←↘↓↘↓↘↘↓↘²η‖O⟲⊗⌕v>^<θ

Draw the left half of the v, then mirror it, then rotate it if the character happens to be >, ^ or <.

Neil

Posted 2018-11-11T19:50:50.373

Reputation: 95 035

Wait, doesn't handle it correctly? – ASCII-only – 2018-11-18T05:01:20.907

@ASCII-only: well, that character isn't in Charcoal's code page, so it can't really appear in the source, can it? – Neil – 2018-11-18T18:03:43.513

If you check it, it's counted as... 3? bytes. I'm not sure if it actually works, but it should - Charcoal should have rudimentary Unicode translation for a certain number of characters after a 0xFF. I'll check later and link if it works – ASCII-only – 2018-11-18T21:45:07.247

here – ASCII-only – 2018-11-18T21:52:03.880

@ASCII-only Ah, I didn't know that about the 0xFF byte. It's a bit confusing because the bytes that the encoded file would need correspond to �﹪⧴ in Charcoal's code page but TIO works in Unicode characters so you can't easily demonstrate that. – Neil – 2018-11-19T00:20:23.077

I'm an idiot and added , it shouldn't actually be there, realized when I was thinking about how the decoding worked - 0xFF will never be translated by itself – ASCII-only – 2018-11-19T00:36:08.857

1

MATL, 9 bytes

1w&XG7lZG

Cheating? Maybe. Try it on MATL Online.

Literal translation of the MATLAB code plot(1,input(''));axis off (26 bytes). The online version compresses the image, but on a local machine it will simply use the MATLAB plot defaults.

Sanchises

Posted 2018-11-11T19:50:50.373

Reputation: 8 530

I guess the consensus is that built-in functions are allowed by default, so no cheating. – anatolyg – 2018-11-12T11:11:43.900

1@anatolyg I know, else I wouldn't have posted it. But it definitely feels like cheating ;) – Sanchises – 2018-11-12T11:51:49.007

0

Python, 58 bytes

from matplotlib.pyplot import*
plot(0,input())
axis('off')

Fun to take advantage of matplotlib doing all the heavy lifting.

Joe Habel

Posted 2018-11-11T19:50:50.373

Reputation: 179