Тёмный

Make Great MATLAB Figures for your Scientific Paper or your PhD Thesis 

PhysicsLaure
Подписаться 1,1 тыс.
Просмотров 26 тыс.
50% 1

A beginner-friendly tutorial to help you make great Matlab figures for your (LaTeX) scientific paper or your PhD thesis, also in Word. Generate professional high-quality plots and figures that work for Latex, PdfTex, Word and PowerPoint. I'll show you how to generate high-quality professional looking plots in figures that can follow the APA guidelines and be accepted in peer-reviewed scientific journals. I used this code for my PhD thesis and my scientific papers, and I wanted to present the information in dark mode, with a minimal but elegant style for your pleasure. I'll walk you through the code line by line including the matlab print function, the matlab set function, the matlab findall function, fontsize in matlab, latex interpreter in matlab and so much more. Our goal is for your to turn your plots and figures into professional graphics and images that can be used in peer-reviewed journals. I use dark mode for your convenience, and show an example in LaTeX. I discuss in particular the fontsize, as 17 or 21 or 32, to make my point clear. The colors come from Monokai Pro dark mode, my favourite color scheme for editing and for Matlab.
The Matlab code _________________________________
hfig = figure; % save the figure handle in a variable
t = 0:0.02:10; x = t.*sin(2*pi*t)+ 2*rand(1,length(t)); % data
plot(t,x,'k-','LineWidth',1.5,'DisplayName','$\Omega(t)$');
xlabel('time $t$ (s)')
ylabel('$\Omega$ (V)')
fname = 'myfigure';
picturewidth = 20; % set this parameter and keep it forever
hw_ratio = 0.65; % feel free to play with this ratio
set(findall(hfig,'-property','FontSize'),'FontSize',17) % adjust fontsize to your document
set(findall(hfig,'-property','Box'),'Box','off') % optional
set(findall(hfig,'-property','Interpreter'),'Interpreter','latex')
set(findall(hfig,'-property','TickLabelInterpreter'),'TickLabelInterpreter','latex')
set(hfig,'Units','centimeters','Position',[3 3 picturewidth hw_ratio*picturewidth])
pos = get(hfig,'Position');
set(hfig,'PaperPositionMode','Auto','PaperUnits','centimeters','PaperSize',[pos(3), pos(4)])
%print(hfig,fname,'-dpdf','-painters','-fillpage')
print(hfig,fname,'-dpng','-painters')
TIMESTAMPS _________________________________
0:00 create great MATLAB figures
0:14 typical matlab figure: issues
0:22 unclear matlab figure
0:28 matlab figure fontsize too small
0:33 matlab different fonts axis vs label
1:03 THE ENTIRE MATLAB CODE!
1:09 Generate matlab figure
1:30 save figure handle as hfig
1:40 create random data in matlab
1:45 plot data with pretty color, thick line, displayname
2:13 label in matlab figure
2:31 MOST INTERESTING PART OF THE CODE!
2:34 picturewidth = 20
2:58 height/weight ratio = 0.65
3:15 findall() and set() functions in matlab example
3:30 set all fontsize in matlab to 17
3:51 box property in matlab figure
4:20 latex interpreter in matlab figure
4:40 tick labels (Ticklabel) in latex in matlab figure
4:54 matlab figure size command
5:03 pdf figure size issue
5:30 print pdf function for matlab figure
5:42 save as png and save as pdf in matlab
6:00 the problem with EPS for LaTeX
6:26 print series of figures in matlab
6:50 HOW TO SET THE BEST FONTSIZE!
7:36 use and install Computer Modern Serif on Windows
8:23 the perfect fontsize
8:30 large fontsize in matlab for PowerPoint
9:09 would you like a tutorial on legends or color schemes?

Опубликовано:

 

16 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 102   
@PhysicsLaure
@PhysicsLaure Год назад
Can you please promote this video on Reddit (in a relevant subreddit)? You'd be an angel!
@anupamag5147
@anupamag5147 2 года назад
Thank you so much! I have been hating my figures on matlab right from the start. I have gone all around internet searching for the perfect code to just plug into every figure I generate instead of having functions and complicating the code. But this was the best and very clearly explained. Thanks again!
@PhysicsLaure
@PhysicsLaure 2 года назад
Glad I could help Anupama ! 💚
@reitrop6273
@reitrop6273 2 года назад
Thank you for the tutorial. I made the switch to Python some months ago, but these are still very useful guidelines (regarding font size, colours, file formats, etc.).
@PhysicsLaure
@PhysicsLaure 2 года назад
Hi! You should def. build a little set of lines to male your figures pretty. It also keeps everything homogeneous ;)
@reitrop6273
@reitrop6273 Год назад
@@PhysicsLaure Thank you for the advice. I’ll certainly do it once my “style” of figures has matured.
@alboTBA
@alboTBA Год назад
Thank you a lot! I was struggling so much with the formatting!
@PhysicsLaure
@PhysicsLaure Год назад
Good luck with it! Also go Bern :)
@Cuneytege1975
@Cuneytege1975 Год назад
Thanks for the tutorial.
@ehsannavvabi6284
@ehsannavvabi6284 Год назад
Nice Work 🤯🤯🤯🤯
@tannguyentrong1142
@tannguyentrong1142 24 дня назад
thank youuuuuuuuuuuuu so muchh
@subhadipkarmakar2841
@subhadipkarmakar2841 Год назад
Thank you very much Madam for this tutorial video😇 from India 🇮🇳
@AhmetFrk347
@AhmetFrk347 Год назад
Thank you for sharing this. Such a great code!
@PhysicsLaure
@PhysicsLaure Год назад
You welcome :)
@QED.
@QED. Год назад
Thanks for explanation, it couldn't be better!
@PhysicsLaure
@PhysicsLaure Год назад
Aww 🥰
@MTauhaA
@MTauhaA 2 года назад
Really useful tips for producing presentable figures from MATLAB. Two file exchange submissions that seem highly relevant here are: 1. Fixfig (This does quite a few things mentioned in the video for font style and marker style in MATLAB graphic objects through typing just one word) 2. export_fig (This produces high-res and correctly cropped figures for exporting from MATLAB)
@PhysicsLaure
@PhysicsLaure 2 года назад
Hey Muhammad, 100% agree on both files. I prefer to have solutions that are independent of them as a rule of thumb, I always end up with issues downloading them, or with people who can't. Thanks for watching this video :D
@MostafaMASLOUHI
@MostafaMASLOUHI 3 месяца назад
Thank you very much. Great work. it would be very nice if you can make a tutorial on legends and color schemes.
@emrahyalcin
@emrahyalcin 2 года назад
it was a very informative video. thanks for sharing. I'll wait for more tips.
@LaureMBrussolo
@LaureMBrussolo 2 года назад
Thanks ^^
@user-nd7rk6dd3p
@user-nd7rk6dd3p 3 месяца назад
Great video
@shane3379
@shane3379 2 года назад
Excellent video, very informative and really well made!
@PhysicsLaure
@PhysicsLaure 2 года назад
Hi Shane! Thanks :D
@youngwoosim2096
@youngwoosim2096 Год назад
really nice!!! would you share your tips on legends and especially color schemes? how do you manage those?
@coolabahwoodworking
@coolabahwoodworking Год назад
That's a gerat video Amazing!
@PhysicsLaure
@PhysicsLaure Год назад
Oh thanks 🧡🧡🧡
@rahulaggarwal08
@rahulaggarwal08 8 месяцев назад
Hi! Thank you so much for a great tutorial! I had been looking for something exactly like this. Just one question- when I print figures using your code, the whitespace/margins around the actual plot are too wide. So when I embed the figure in any document, the actual plot looks smaller. Is there a fix for this?
@mustafaalshaqaq2303
@mustafaalshaqaq2303 2 года назад
Nice! I liked your way of creating figures. Keep up the good work. One comment though is the "TickLength" property does not adjust well especially if you want to create small figures. I had this issue before and I always wanted to find a way to automatically take care of this issue. Also, I had this issue of the default black color used for labels, axes, ticks, etc. is not really black, I believe the default is [0.15 0.15 0.15]. I just wanted to mention this because especially in LaTeX the font is black and sometimes it becomes clear that the figure fonts are a bit lighter than the text in latex. Thanks.
@LaureMBrussolo
@LaureMBrussolo 2 года назад
Hey! Thanks for the feedback on the color. I'm going to check. Agree on TickLength, I often end up manually setting value ranges -_-
@LaureMBrussolo
@LaureMBrussolo 2 года назад
Usually for ticks, I know what range I have so I set either both bounds + 1/2 ticks in the middle, or every specific values. You can set ax.XTick = -1000:1000 and it'll only show the relevant numbers 😉 For the first thing, it's just ax.XTick = ax.XLim :)
@sidchen5695
@sidchen5695 2 года назад
Thanks,helps a lot!
@LaureMBrussolo
@LaureMBrussolo 2 года назад
Yay ^^
@tongxin6516
@tongxin6516 Год назад
Great job!
@PhysicsLaure
@PhysicsLaure Год назад
Thanks, Tong ! :)
@venkatprasadpadhy1656
@venkatprasadpadhy1656 10 месяцев назад
Thank you for the nice explanation, but you have not discussed about removing the whitespaces around the plot, can you please...
@mustaphamustapha3881
@mustaphamustapha3881 2 года назад
Thanks, good job
@PhysicsLaure
@PhysicsLaure 2 года назад
Thanks ! ^^
@oleskarjsok9392
@oleskarjsok9392 Год назад
Do you have a good way of setting up the colorbar text?
@mathijslemmens9727
@mathijslemmens9727 8 месяцев назад
Thank you for your advice. My plots look way better this way. However, when I try to save each figure as a PDF file, I run into a problem. The PDF that is saved only displays a small area of the total plot. I tried to experiment with different width and hw-ratios, but it did not work
@experimentariumciencia
@experimentariumciencia 2 года назад
Thank You for this great video. Ivan Experimentarium Brazil
@PhysicsLaure
@PhysicsLaure 2 года назад
Hi Ivan! Thanks for watching :)
@jerichocz8079
@jerichocz8079 8 месяцев назад
Love u
@hishan.farfan
@hishan.farfan Год назад
Thank you so much!
@PhysicsLaure
@PhysicsLaure Год назад
😊
@tilkesh
@tilkesh Год назад
thx
@farhazexplains
@farhazexplains 6 месяцев назад
Can you please help me how you create your videos? I really like the style.
@VisualVEN0M
@VisualVEN0M 2 года назад
Amazing video
@PhysicsLaure
@PhysicsLaure 2 года назад
Thanks! ^^
@ScuffedF1
@ScuffedF1 6 месяцев назад
Hiya, I've got some questions as I am having issues implementing your code. Taking 1:08 as a screenshot, your code is split into two parts. For the part of the code "Picturewidth..." and below, do I need to copy this after every single figure I create on MATLAB or can I include it at the bottom of my document and be done with it? It would be cool if you could share a document showing the implementation of your code within a MATLAB livescript rather than in isolation (to made it idiot proof haha). Appreciate the work Ciao
@henriquethetraiN
@henriquethetraiN 6 месяцев назад
How to save each graphic element separately in png?
@SSoIo
@SSoIo Год назад
Excellent video and code, thank you for sharing :) Was just wondering if we would need to reference you in some way for using the code and if so, how?
@PhysicsLaure
@PhysicsLaure Год назад
You can quote PhysicsLaure if you'd like but otherwise feel free to use the code. I'm team OpenSource on that kind of things 💚
@SSoIo
@SSoIo Год назад
@@PhysicsLaure Wonderful, thanks again ❤
@marce-work
@marce-work 5 месяцев назад
Wow! you are amazing for sharing these secrets with us
4 месяца назад
I have the same question about legend, have you found a solution? :)
@filipe.tavares
@filipe.tavares 2 года назад
Hi, Thank you for the tutorial! I really appreciate it!! By the way, what is the editor you use for Matlab scripts? And what is this color scheme and font style? It looks amazing
@PhysicsLaure
@PhysicsLaure Год назад
Happy you like it Filipe! I made the text in the ideo editor itself. I use one of the dark theme Monokai (my favourite) 😉
@josetjaw8161
@josetjaw8161 10 месяцев назад
I use matlab in vscode just to be able to use theme. And monokai is one of my fav theme too! 😁
@Axelfotze
@Axelfotze Год назад
Thank you so much for sharing this! This is great! I however like to crop the PDF so there will be no white borders. I just replaced :"print(hfig,fname,'-dpdf','-painters','-fillpage')" with "exportgraphics(hfig, strcat(fname,'.pdf'), 'ContentType', 'vector');"
@PhysicsLaure
@PhysicsLaure Год назад
Hi Haroun! I didn't know about that function!! Cool ^^
@helderfn
@helderfn 9 месяцев назад
Is there a way to do this in Octave? I need to remove the withe borders too.
@gauravmediratta2926
@gauravmediratta2926 7 месяцев назад
Would you be able to make a tutorial/ share code on how to create a good legend?
@jrgenmyklebust5157
@jrgenmyklebust5157 Год назад
can you share the color vectors you are using? great vid!
@PhysicsLaure
@PhysicsLaure Год назад
Hey! I copy pasted the colormapa developed for matplotlib (magma & co) as they are very pretty :)
@kingsoz3372
@kingsoz3372 Год назад
How do you include the legend with the proposed matlab code in the video? Thanks
@PhysicsLaure
@PhysicsLaure Год назад
You use DisplayName when you plot to set the label of each legend entry, then simply lg=legend('show');
@freemanmeno2709
@freemanmeno2709 Год назад
Great content! I tried running it in a FOR loop but I get errors on the figure handles. I created a list of figure handles a I let hfig go through the list but it only works for the first element of my list.
@PhysicsLaure
@PhysicsLaure Год назад
Hey! I don't have the code on hand by arrays of figures are difficult. from memory I stored it in a cell array, and write: myaxis{i} = figure; Hope you find your problem!
@freemanmeno2709
@freemanmeno2709 Год назад
@@PhysicsLaure thanks! I will try it out
@codeparity
@codeparity 2 года назад
how do you add space between the labels and the axis
@PhysicsLaure
@PhysicsLaure 2 года назад
You can set the position of each label, I'd typically do mylabel.Position(x) = mylabel.Position(x)+0.1
@40NoNameFound-100-years-ago
Hello, Thanks for such a great video. I have a question regarding the output pdf file. Now, In case I am writing a research paper and the paper has two columns, suppose I will place the pdf image in one of the columns and not in the middle of the paper, what is the suitable width I should choose for the pdf file when I use : \includegraphics[width=??]{filename.filetype}.....thanks again
@PhysicsLaure
@PhysicsLaure Год назад
Hi Mohamed! I'd recommemd you manually try it out to see. I usually keep the width at 0.6 and adapt the fontsize until I'm happy with how it fits in the paper. The cool thing is that you can do it on any figure, and it'll work for all :)
@henriquethetraiN
@henriquethetraiN 6 месяцев назад
@@PhysicsLaure How to save each graphic element separately in png?
@christiancahig2269
@christiancahig2269 Год назад
Is it possible to have an object-oriented way of handling figures and axes?
@PhysicsLaure
@PhysicsLaure Год назад
You can have arrays of handle yes. I did it a couple times. Something like listaxes{i} = axes(...);
@jamesengstrom4098
@jamesengstrom4098 2 года назад
I need pretty colours for my legends and colour schemes pls
@PhysicsLaure
@PhysicsLaure 2 года назад
I'm a fan of matlplotlib's colorscheme. You can "steal" them if you can get the array of 3D value. Copy-paste it in excel or directly in Matlab, and you have a new colorscheme :)
@yazanmostafa6813
@yazanmostafa6813 2 года назад
How do I add a straight line that belongs to some curved points It ends at x=0
@PhysicsLaure
@PhysicsLaure 2 года назад
Hi ! plot([0, x], [o, y],'-')
@hahaxd9497
@hahaxd9497 Год назад
I always get the Error after copypasting the code: Error using matlab.graphics.internal.name (line 101) Cannot create output file '.\myfigure.png'. Error in print (line 71) pj = matlab.graphics.internal.name( pj ); Error in Graphenfürmodulation (line 71) print(hfig,fname,'-dpng','-painters')
@PhysicsLaure
@PhysicsLaure Год назад
Hey! Try without the ".\" in the print command. Otherwise you might not have the rights to create a new file 🤔
@hahaxd9497
@hahaxd9497 Год назад
Ah thank you! Now it works
@waseemshameer3275
@waseemshameer3275 Год назад
What to do if i have multiple figures in the same figure? Also with picturewidth = 20, the figure is shifted to the right a lot in my Latex document
@PhysicsLaure
@PhysicsLaure Год назад
It's shifted to the right bc 20 is too wide for your document. Decrease it til you like it. For the several figures it works just as normal but you need to learn how to manage them (an entire topic in itself 😂)
@waseemshameer3275
@waseemshameer3275 Год назад
@@PhysicsLaure Thank you for the reply, what are the margins you use on your documents?
@PhysicsLaure
@PhysicsLaure Год назад
@@waseemshameer3275 the ones in the video 😅
@dr.imrankhanyousufzai4710
@dr.imrankhanyousufzai4710 Год назад
I'm unable to make the labels and ticks "bold" using your code. Can you please guide
@PhysicsLaure
@PhysicsLaure Год назад
Off the top of my head, you can set boldness with the FontWeight parameters (copy paste the line setting the font for everything, and try using it with fontweight". 🤔
@dr.imrankhanyousufzai4710
@dr.imrankhanyousufzai4710 Год назад
@@PhysicsLaure Thanks for the reply. Actually I tried "FontWeight",'b'. but its not working with the current code. If interpreter is not set to 'latex' then it work.
@shayanroohbakhsh9321
@shayanroohbakhsh9321 Год назад
cool
@PhysicsLaure
@PhysicsLaure Год назад
Thanks Shayan! ^^
@shtrafnoy
@shtrafnoy Год назад
We're still waiting your tutorial on legends and color schemes?🙃
@PhysicsLaure
@PhysicsLaure Год назад
Haha! I might do it but I need to use my old computer that has matlab 😂
@heictorcosta4242
@heictorcosta4242 2 месяца назад
@@PhysicsLaure We will be waiting
@sadiq114
@sadiq114 Год назад
Thanks a lot for your video. But How will we plot a figure already published in a paper. I mean if we want to plot a figure given in a published paper ourselves, how will we plot it in MATLAB as we have no data of that figure. If you can make a video on it, it will be very kind of you.
@PhysicsLaure
@PhysicsLaure Год назад
automeris.io/WebPlotDigitizer/ is the magic tool you want. But it's a solid video idea, thanks for suggesting it! :D
@user-rz4lx2wd7p
@user-rz4lx2wd7p 7 месяцев назад
Great stuff. I made it into a nice function that I have in my 'general ' library if anyone's interested (it uses "exportgraphics" instead of "print", which I find much nicer): function printfigure(filename,options) % Code taken from youtube video: % "ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-wP3jjk1O18A.html" % by PhysicsLaure. arguments filename options.columntype string {ismember(options.columntype,["single","double"])} = "single"; options.fig = gcf; options.hw_ratio double {mustBePositive} = 0.65; options.fontsize double {mustBePositive} = 10; options.filetype string {ismember(options.filetype,["pdf","png"])} = "pdf"; end hfig = options.fig; hw_ratio = options.hw_ratio; % feel free to play with this ratio fontsize = options.fontsize; % adjust fontsize to your document if options.columntype == "single" picturewidth = 15; % set this parameter and keep it forever for continuity in your work elseif options.columntype == "double" picturewidth = 9; % set this parameter and keep it forever for continuity in your work else error('invalid columntype.') end set(findall(hfig,'-property','FontSize'),'FontSize',fontsize) set(findall(hfig,'-property','Box'),'Box','off') % optional set(findall(hfig,'-property','Interpreter'),'Interpreter','latex') set(findall(hfig,'-property','TickLabelInterpreter'),'TickLabelInterpreter','latex') set(hfig,'Units','centimeters','Position',[3 3 picturewidth hw_ratio*picturewidth]) pos = get(hfig,'Position'); set(hfig,'PaperPositionMode','Auto','PaperUnits','centimeters','PaperSize',[pos(3), pos(4)]) if options.filetype == "pdf" exportgraphics(hfig,[char(filename),'.pdf'],'ContentType','vector') elseif options.filetype == "png" exportgraphics(hfig,[char(filename),'.png'],'ContentType','image') else error('Invalid filetype.') end end
@swaree
@swaree Месяц назад
many thanks!
@user-rz4lx2wd7p
@user-rz4lx2wd7p Месяц назад
@@swaree No problem🙂 glad someone found it useful
Далее
Creating Movies and Animations in Matlab
27:01
Просмотров 113 тыс.
Кто сделал Катар богатым? #shorts
0:59
The REAL Three Body Problem in Physics
16:20
Просмотров 137 тыс.
Mindset of Successful Programmers
4:56
Просмотров 999 тыс.
How to MASSIVELY enhance clarity in your science figures
1:01:23
MATLAB to C Made Easy - R2017a
55:48
Просмотров 40 тыс.
How I make science animations
43:39
Просмотров 701 тыс.
Vim Motions for absolute beginners!!!
7:25
Просмотров 153 тыс.
Brain Criticality - Optimizing Neural Computations
37:05
Export High Quality Figure 600dpi in MATLAB
11:44
Просмотров 1,2 тыс.