-
Notifications
You must be signed in to change notification settings - Fork 57
/
matlab_graphics.html
569 lines (493 loc) · 18.3 KB
/
matlab_graphics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
<html>
<head>
<title>
MATLAB_GRAPHICS - How Do You Do That?
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
MATLAB_GRAPHICS <br> How Do You Do That?
</h1>
<hr>
<p>
<b>MATLAB_GRAPHICS</b>
is a directory of MATLAB programs which
illustrate how to achieve relatively simple graphics effects
that are TRIVIAL when using a pencil, SIMPLE when using any
standard graphics package, but seem to be IMPOSSIBLE
when struggling with MATLAB's stunningly elaborate and awkward
graphics system.
</p>
<p>
I love MATLAB, I really do, but if the default behavior of MATLAB's
graphic system doesn't work for you, it seems to me excruciatingly
painful to discover a technique for getting what you want - moreover,
there rarely seems to be a sensible logical structure to explain
what is going on, nor a systematic procedure for building an image.
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files made available on this web page
are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../m_src/area_under_curve/area_under_curve.html">
AREA_UNDER_CURVE</a>,
a MATLAB function which
displays the area under a curve, that is, the points (x,y)
between the X axis and the curve Y=F(X).
</p>
<p>
<a href = "../../m_src/ball_and_stick_display/ball_and_stick_display.html">
BALL_AND_STICK_DISPLAY</a>,
a MATLAB program which
demonstrates the creation of a 3D ball and stick image;
</p>
<p>
<a href = "../../m_src/bezier_surface_display/bezier_surface_display.html">
BEZIER_SURFACE_DISPLAY</a>,
a MATLAB program which
displays a Bezier surface;
</p>
<p>
<a href = "../../m_src/box_display/box_display.html">
BOX_DISPLAY</a>,
a MATLAB program which
displays a box plot, over integer pairs of data, of a function
defined by two formulas.
</p>
<p>
<a href = "../../m_src/cavity_flow_display/cavity_flow_display.html">
CAVITY_FLOW_DISPLAY</a>,
a MATLAB program which
displays a single velocity field solution for the driven cavity;
</p>
<p>
<a href = "../../m_src/cc_display/cc_display.html">
CC_DISPLAY</a>,
a MATLAB program which
displays the points used in a 2D Clenshaw-Curtis quadrature rule;
</p>
<p>
<a href = "../../m_src/fd1d_display/fd1d_display.html">
FD1D_DISPLAY</a>,
a MATLAB program which
reads a pair of files defining a 1D finite difference model,
and plots the data.
</p>
<p>
<a href = "../../m_src/fem_basis_q4_display/fem_basis_q4_display.html">
FEM_BASIS_Q4_DISPLAY</a>,
a MATLAB program which
displays a finite element method (FEM) basis function
associated with a linear quadrilateral (Q4) mesh.
</p>
<p>
<a href = "../../m_src/fem_basis_t3_display/fem_basis_t3_display.html">
FEM_BASIS_T3_DISPLAY</a>,
a MATLAB program which
displays a finite element method (FEM) basis function
associated with a 3-node triangle (T3) mesh.
</p>
<p>
<a href = "../../m_src/fem_basis_t4_display/fem_basis_t4_display.html">
FEM_BASIS_T4_DISPLAY</a>,
a MATLAB program which
displays a finite element method (FEM) basis function
associated with a 4-node triangle (T4) mesh.
</p>
<p>
<a href = "../../m_src/fem_basis_t6_display/fem_basis_t6_display.html">
FEM_BASIS_T6_DISPLAY</a>,
a MATLAB program which
displays a finite element method (FEM) basis function
associated with a 6-node triangle (T6) mesh.
</p>
<p>
<a href = "../../m_src/fem1d_display/fem1d_display.html">
FEM1D_DISPLAY</a>,
a MATLAB program which
reads three files defining a 1D arbitrary degree finite element function,
and displays a plot.
</p>
<p>
<a href = "../../m_src/fem1d_function_10_display/fem1d_function_10_display.html">
FEM1D_FUNCTION_10_DISPLAY</a>,
a MATLAB program which
reads three files defining a 1D piecewise linear finite element function
and displays a plot.
</p>
<p>
<a href = "../../m_src/gl_display/gl_display.html">
GL_DISPLAY</a>,
a MATLAB program which
displays the points used in a 2D Gauss-Legendre quadrature rule;
</p>
<p>
<a href = "../../m_src/gray_code_display/gray_code_display.html">
GRAY_CODE_DISPLAY</a>,
a MATLAB program which
computes the Hamming distance tables for both the binary and Gray codes,
and displays 3D plots that illustrate how the Gray code does a better job
of providing nearby representations for nearby numbers.
</p>
<p>
<a href = "../../m_src/grf_display/grf_display.html">
GRF_DISPLAY</a>,
a MATLAB program which
reads a GRF file defining a mathematical graph and
displays it in the MATLAB graphics window.
</p>
<p>
<a href = "../../m_src/grid_display/grid_display.html">
GRID_DISPLAY</a>,
a MATLAB program which
reads a file of points on a grid or sparse grid, displays the grid and
saves the image in a Portable Network Graphics (PNG) file;
</p>
<p>
<a href = "../../m_src/grids_display/grids_display.html">
GRIDS_DISPLAY</a>,
a MATLAB program which
reads two files of grids or sparse grids, displays the first with
hollow blue dots, the second with red dots.
</p>
<p>
<a href = "../../m_src/hcell_flow_display/hcell_flow_display.html">
HCELL_FLOW_DISPLAY</a>,
a MATLAB program which
plots the physical data, pressures or velocities,
from a run of the hcell program;
</p>
<p>
<a href = "../../m_src/hermite_product_display/hermite_product_display.html">
HERMITE_PRODUCT_DISPLAY</a>,
a MATLAB program which
displays an image of a function created by the Cartesian product of two
Hermite polynomials, such as f(x,y) = h(3,x) * h(1,y).
</p>
<p>
<a href = "../../m_src/histogram_display/histogram_display.html">
HISTOGRAM_DISPLAY</a>,
a MATLAB program which
makes a bar plot of a set of data stored
as columns in a file; the first column is the X values, and
all the other columns are Y values to be shown as a stack of bars;
</p>
<p>
<a href = "../../m_src/inout_flow_display/inout_flow_display.html">
INOUT_FLOW_DISPLAY</a>,
a MATLAB library which
displays a single velocity field solution for the inout flow;
</p>
<p>
<a href = "../../m_src/lagrange_basis_display/lagrange_basis_display.html">
LAGRANGE_BASIS_DISPLAY</a>,
a MATLAB library which
displays the basis functions associated with a given set of nodes used
with the Lagrange interpolation scheme.
</p>
<p>
<a href = "../../m_src/mesh_display/mesh_display.html">
MESH_DISPLAY</a>,
a MATLAB program which
reads data defining a polygonal mesh and displays it, with optional
numbering.
</p>
<p>
<a href = "../../m_src/moc_display/moc_display.html">
MOC_DISPLAY</a>,
a MATLAB program which
estimates and displays the modulus of continuity function for a given
function F(X) over a finite interval [A,B], using N sample values.
</p>
<p>
<a href = "../../m_src/mpas_grid_display/mpas_grid_display.html">
MPAS_GRID_DISPLAY</a>,
MATLAB programs which
can read an MPAS netcdf grid file and display the primary polygonal
mesh or the dual triangular mesh.
</p>
<p>
<a href = "../../m_src/nested_sequence_display/nested_sequence_display.html">
NESTED_SEQUENCE_DISPLAY</a>,
a MATLAB program which
displays a set of nested sequences.
</p>
<p>
<a href = "../../m_src/obj_display/obj_display.html">
OBJ_DISPLAY</a>,
a MATLAB program which
reads an OBJ 3D graphics file and displays it on the screen.
</p>
<p>
<a href = "../../m_src/ply_display/ply_display.html">
PLY_DISPLAY</a>,
a MATLAB program which
displays an image of a 3D graphics file in PLY format;
</p>
<p>
<a href = "../../m_src/polygonal_surface_display/polygonal_surface_display.html">
POLYGONAL_SURFACE_DISPLAY</a>,
a MATLAB program which
displays a surface in 3D described as a set of polygons;
</p>
<p>
<a href = "../../m_src/quad_mesh_order1_display/quad_mesh_order1_display.html">
QUAD_MESH_ORDER1_DISPLAY</a>,
a MATLAB program which
plots piecewise constant data associated with a mesh of quadrilaterals;
</p>
<p>
<a href = "../../m_src/quad_surface_display/quad_surface_display.html">
QUAD_SURFACE_DISPLAY</a>,
a MATLAB program which
plots piecewise bilinear data associated with a QUAD_SURFACE, that is,
a 3D surface defined by a quadrilateral mesh;
</p>
<p>
<a href = "../../m_src/sequence_streak_display/sequence_streak_display.html">
SEQUENCE_STREAK_DISPLAY</a>,
a MATLAB program which
displays a streak plot of a numeric sequence;
</p>
<p>
<a href = "../../m_src/shallow_water_1d_display/shallow_water_1d_display.html">
SHALLOW_WATER_1D_DISPLAY</a>,
a MATLAB program which
can display a solution of the shallow water equations in 1D,
generally as computed by the program shallow_water_1d.
</p>
<p>
<a href = "../../m_src/sphere_lebedev_rule_display/sphere_lebedev_rule_display.html">
SPHERE_LEBEDEV_RULE_DISPLAY</a>,
a MATLAB program which
reads a file defining a Lebedev quadrature rule for the unit sphere and
displays the point locations.
</p>
<p>
<a href = "../../m_src/sphere_stereograph_display/sphere_stereograph_display.html">
SPHERE_STEREOGRAPH_DISPLAY</a>,
a MATLAB library which
computes and displays the results of several stereographic projections
between a sphere and a plane.
</p>
<p>
<a href = "../../m_src/sphere_xyz_display/sphere_xyz_display.html">
SPHERE_XYZ_DISPLAY</a>,
a MATLAB program which
reads XYZ information defining points in 3D,
and displays a unit sphere and the points in the MATLAB 3D graphics window.
</p>
<p>
<a href = "../../m_src/sphere_xyzf_display/sphere_xyzf_display.html">
SPHERE_XYZF_DISPLAY</a>,
a MATLAB program which
reads XYZF information defining points and faces,
and displays a unit sphere, the points, and the faces,
in the MATLAB 3D graphics window. This can be used, for instance, to
display Voronoi diagrams or Delaunay triangulations on the unit sphere.
</p>
<p>
<a href = "../../m_src/stla_display/stla_display.html">
STLA_DISPLAY</a>,
a MATLAB program which
reads an ASCII stereolithography (STL) file and displays it on the screen.
</p>
<p>
<a href = "../../m_src/tcell_flow_display/tcell_flow_display.html">
TCELL_FLOW_DISPLAY</a>,
a MATLAB library which
displays a single velocity field solution for the T cell;
</p>
<p>
<a href = "../../m_src/tensor_grid_display/tensor_grid_display.html">
TENSOR_GRID_DISPLAY</a>,
a MATLAB program which
can display the grid points of a tensor product rule used for
interpolation or quadrature, in 1D, 2D or 3D.
</p>
<p>
<a href = "../../m_src/tet_mesh_display/tet_mesh_display.html">
TET_MESH_DISPLAY</a>,
a MATLAB program which
reads in the node and element files defining a tet mesh
and displays a wireframe image.
</p>
<p>
<a href = "../../m_src/tetrahedron_slice_display/tetrahedron_slice_display.html">
TETRAHEDRON_SLICE_DISPLAY</a>,
a MATLAB program which
determines the intersection between a tetrahedron and a plane and
displays the result.
</p>
<p>
<a href = "../../m_src/tri_surface_display/tri_surface_display.html">
TRI_SURFACE_DISPLAY</a>,
a MATLAB program which
displays the 3D graphics information
in a TRI_SURFACE file;
</p>
<p>
<a href = "../../m_src/triangle_display/triangle_display.html">
TRIANGLE_DISPLAY</a>,
a MATLAB program which
displays the nodes and elements of a triangulation
on the MATLAB graphics screen, assuming the data has been
stored in NODE and ELE files by the TRIANGLE program.
</p>
<p>
<a href = "../../m_src/triangulation_display/triangulation_display.html">
TRIANGULATION_DISPLAY</a>,
a MATLAB program which
displays the nodes and elements of a triangulation
on the MATLAB graphics screen;
</p>
<p>
<a href = "../../m_src/triangulation_order1_display/triangulation_order1_display.html">
TRIANGULATION_ORDER1_DISPLAY</a>,
a MATLAB program which
plots piecewise constant data associated with a triangulation;
</p>
<p>
<a href = "../m_src/voronoi_display/voronoi_display.html">
VORONOI_DISPLAY</a>,
a MATLAB program which
computes the exact Voronoi diagram using geompack, and displays it.
</p>
<p>
<a href = "../../m_src/xy_display/xy_display.html">
XY_DISPLAY</a>,
a MATLAB program which
reads XY information defining points in 2D,
and displays an image in a MATLAB graphics window;
</p>
<p>
<a href = "../../m_src/xyf_display/xyf_display.html">
XYF_DISPLAY</a>,
a MATLAB program which
reads XYF information defining points and faces in 2D,
and displays an image in a MATLAB graphics window.
</p>
<p>
<a href = "../../m_src/xyl_display/xyl_display.html">
XYL_DISPLAY</a>,
a MATLAB program which
reads XYL information defining points and lines in 2D,
and displays an image in a MATLAB graphics window.
</p>
<p>
<a href = "../../m_src/xyz_display/xyz_display.html">
XYZ_DISPLAY</a>,
a MATLAB program which
reads XYZ information defining points in 3D,
and displays an image in the MATLAB graphics window.
</p>
<p>
<a href = "../../m_src/xyzf_display/xyzf_display.html">
XYZF_DISPLAY</a>,
a MATLAB program which
reads XYZF information defining points and faces in 3D,
and displays an image using OpenGL.
</p>
<p>
<a href = "../../m_src/xyzl_display/xyzl_display.html">
XYZL_DISPLAY</a>,
a MATLAB program which
reads XYZL information defining points and lines in 3D,
and displays an image in a MATLAB graphics window.
</p>
<h3 align = "center">
Source Code:
</h3>
<p>
You plot a circle, and it comes out an ellipse. What is going on?
Briefly, MATLAB uses a rectangle to display your plot. It takes
the X and Y ranges of your data, and stretches them along the horizontal
and vertical directions of the rectangle. This guarantees that a
plot that is logically square will be displayed as a rectangle,
and thus a circle becomes an ellipse. Luckily, the "axis equal"
command helps. MATLAB still plots inside a rectangle, but now
it stretches your X and Y data by the same single scale factor,
resulting in some new white space to the left and right of your
plot of a perfect circle.
<ul>
<li>
<a href = "circle_test.m">circle_test.m</a>,
a program that plots a circle twice, the second time using
the "axis square" command.
</li>
<li>
<a href = "circle_test01.png">circle_test01.png</a>,
the first circle (which looks like an ellipse).
</li>
<li>
<a href = "circle_test02.png">circle_test02.png</a>,
the second version of the circle, which looks OK.
</li>
</ul>
</p>
<p>
Surprisingly, a typical MATLAB plot can involve a lot of empty
space. In the simple case where you are plotting a circle, you
will get white space in the grid region itself if you enforce
equal axis units, since MATLAB wants to display the grid within
a rectangle. But you will also get a substantial margin of white
space around the plot area itself. This can be annoying when you
are trying to prepare graphics for use in a publication, or
if you want to put several images side by side - the white space,
which contains no information, eats up lots of space.
</p>
<p>
Can you cut back that white space? In particular, if you want to
plot a circle (or anything else whose shape doesn't correspond to
MATLAB's "golden rectangle"), can you make an image that is
mathematically correct, and economic in terms of wasted white space?
</p>
<p>
You may try various combinations of "axis equal", "axis square",
"axis tight", "axis ( [0,1,0,1] )" and so on, all the time coming
halfway to your goal, without ever actually achieving an image
that is square (or whatever aspect ratio you want), doesn't have
wasted graph space, and doesn't have that excessive margin around
the plot.
</p>
<p>
After wasting a lot of time, I stumbled across a few commands that,
used together, seem to achieve the correct result. However, in my
case, the image still looks rectangular in the MATLAB interactive
viewer - but comes out nice and square in the PNG image rendered
by the PRINT command.
<ul>
<li>
<a href = "trim_test.m">trim_test.m</a>,
a program that plots a circle twice, the second time
with the "fat" trimmed off.
</li>
<li>
<a href = "trim_test01.png">trim_test01.png</a>,
the first version of the circle.
</li>
<li>
<a href = "trim_test02.png">trim_test02.png</a>,
the second version of the circle.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../m_src.html">
the MATLAB source codes</a>.
</p>
<hr>
<i>
Last revised on 30 May 2013.
</i>
<!-- John Burkardt -->
</body>
</html>