otter
otter

Reputation: 93

Can`t plot matrix in Gnuplot

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.

Upvotes: 2

Views: 3057

Answers (2)

Matthew
Matthew

Reputation: 7590

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.

Upvotes: 3

bibi
bibi

Reputation: 3765

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

Upvotes: -1

Related Questions