官术网_书友最值得收藏!

Making a scatterplot

If you are in possession of a collection of measurements that, as is usually the case, is subject to random errors, an attempt to simply plot a curve through the measurements may result in a chaotic graph that will be difficult to interpret. In these cases, one usually begins with a scatterplot, which is simply a plot of a dot or small symbol at each data point. An examination of such a plot often leads to the discovery of correlations or patterns.

Making a scatterplot

Getting ready

To make this recipe interesting, we need some slightly random-looking data. You may have some available, in which case you merely need to ensure that it is in a format that gnuplot can read. Simply arrange the data so that each line of the file contains one data point with space-separated x and y values:

x1 y1
x2 y2
...

Then name the file scatter.dat.

If you don't have such a file of your own handy, use the one called scatter.dat that we have provided. Make sure that the file is in the directory in which you have started gnuplot, so that the program can find it.

How to do it…

Tip

Some of the recipes in this book will not work as intended if entered in the same interactive session unless you give the reset command first. This is because these scripts make settings that change gnuplot's default behavior.

Now simply tell gnuplot:

plot 'scatter.dat' with points pt 7

If you are using the file we provided, you will get a plot similar to the one shown in the previous figure.

There's more…

You can plot the points using different symbols. Try plot 'scatter.dat' with dots to get the smallest dot available to your terminal. For use with scatterplots of very large datasets, try the following command:

plot 'scatter.dat' with points pt n

With different integers for n. pt stands for pointtype, and the different pointtypes available are dependent on your terminal. Simply type test in gnuplot to see a demonstration of all the pointtypes available for the currently selected terminal. You can find more about point and line styles in Chapter 3, Applying Colors and Styles.

主站蜘蛛池模板: 德保县| 定西市| 舞钢市| 曲麻莱县| 阿图什市| 巴青县| 敦化市| 上思县| 平南县| 建瓯市| 石林| 楚雄市| 灵璧县| 武胜县| 孟州市| 邢台县| 凯里市| 徐州市| 志丹县| 和林格尔县| 余姚市| 西华县| 饶阳县| 乐业县| SHOW| 通河县| 禄丰县| 云林县| 万安县| 中江县| 高州市| 屏东市| 马边| 社会| 岱山县| 巴里| 绿春县| 宜兰市| 乳源| 喀喇沁旗| 香河县|