This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
it_matlab_figures [2024/03/23 23:30] trinh |
it_matlab_figures [2025/02/07 16:06] (current) trinh |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Generating nice images in Matlab ====== | ====== Generating nice images in Matlab ====== | ||
- | You may be using Matlab to create graphics. Some considerations: | + | Here are some brief details and tips for developing a good workflow for generating publication-quality images. |
- | - Save all data or all scripts. Get in the habit of save data as '' | + | ===== A workflow for saving images ===== |
- | - Similar to above, you may want to save '' | + | |
- | - Use [[https:// | + | |
- | Once you have downloaded the '' | + | As you become a more experienced researcher, you will learn the value of developing a workflow where images can be easily re-generated. This means that you can easily replot the images when you are finalising the presentation. |
+ | |||
+ | - **Rule:** Save all data or all scripts. Get in the habit of saving data as '' | ||
+ | - **Tip: use scripts to generate your figures.** Create scripts that will load in '' | ||
+ | - **Tip: save your figures as .fig.** Similar to above, you may want to save '' | ||
+ | |||
+ | ===== Exporting figures ===== | ||
+ | |||
+ | Traditionally (meaning literally in the last 20 years), Matlab has had very poor ability to generate publication-quality images. Problems include: poor bounding boxes, weird rasterisation effects, weird layering issues, etc. | ||
+ | |||
+ | **Always, always, always** whenever possible, export your images in PDF. This is currently the best format for including into LaTex. When done in the vectorised format of a PDF, the image is then scalable. | ||
+ | |||
+ | There are exceptions to the above rule in the context of images that are extremely data-hungry (thousands of points) or involve 3D surfaces, contour plots, etc. In those cases, the export to PDF can cause file sizes that are too large, or can cause weird layering effects (due to the complexity of rendering a surface, say). In those cases, you want to export to a rasterised format like PNG. | ||
+ | |||
+ | Use [[https:// | ||
+ | |||
+ | Once you have downloaded the '' | ||
+ | |||
+ | <code matlab> | ||
+ | export_fig ' | ||
+ | </ | ||
+ | |||
+ | in order to produce a PDF of the currently focused figure. | ||
+ | |||
+ | ===== Annotations ===== | ||
+ | |||
+ | In order to add annotations to figures, you have a few options: | ||
+ | |||
+ | - Add the annotation natively within Matlab using commands like text(...); this is a good idea in combination with scripts. | ||
+ | - Add the annotation afterwards by using a vector editor like [[https:// | ||
+ | - Use a native LaTeX package like tikz or [[https:// | ||
+ | |||
+ | |||
+ | ===== Advanced ===== | ||
+ | |||
+ | More ' | ||
+ | |||
+ | Post-2010 there have been very powerful scripts that allow Matlab figures to be automatically converted to TiKZ, such as [[https:// | ||
+ | |||
+ | If you are an undergrad student or under pressure to write a report, I don't recommend trying to learn this! | ||