2
votes

I have a matrix of 1s and 0s saved in file. It looks like this:

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

I am trying to plot in gnuplot using command:

    plot 'data.rtf' matrix with image

but when I do that I get an error:

    warning: matrix contains missing or undefined values
    Matrix does not represent a grid

I think I should get an image where 0 is white space and 1 is black space. I am new to gnuplot so i have no idea what might be wrong nor if i am using correct way to do it. I will be grateful for any help. Thanks.

2
Copy&pasting your data snippet and executing your command works fine for me (gnuplot 4.6.6 and 5.0). Did you have any other settings? Put a reset before the plot command to check again. Or your actual data file has some strange hidden characters. Could you upload your original data file somewhere with which you get this error? - Christoph
I tried reset, but didn't work. My version of gnu plot 5.0 patchlevel 1 and i am running in OS X 10.11.2. Also I noticed that my terminal type is set 'aqua'. I am not sure if it is a default type setting for mac, but i don't think I changed that. I have no idea, why it doesn't work, I searched different websites and this works on what I need to do. - otter
And here is my file, which i am trying to plot: dropbox.com/s/rhx1ks5va3a0l6q/data.rtf?dl=0 - otter

2 Answers

3
votes

Your file is an rtf (rich text format) file which is a markup language format, which gnuplot will not understand. You will need to create the file in a text editor (not a word processor) in order to be able to use it.

The file that you provided looks like:

{\rtf1\ansi\ansicpg1250\cocoartf1404\cocoasubrtf340
{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0

\f0\fs22 \cf0 \CocoaLigature0 0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 1\
0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 1 1 0\
0 0 0 0 0 1 1 0 0 0\
1 1 1 1 1 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 0

Notice that it starts with a bunch of markup text. Gnuplot is designed to work with text files and not formatted text or binary files (with some limited exceptions).

Creating a text file containing your designed matrix will work just fine.

0
votes

Color plots are surface-like plots, thus you have to use splot not plot

set pm3d map
set palette gray
splot 'test.txt' matrix w image