{"id":334,"date":"2022-02-14T02:17:53","date_gmt":"2022-02-13T18:17:53","guid":{"rendered":"https:\/\/www.scijournal.org\/articles\/?p=334"},"modified":"2023-05-22T06:12:28","modified_gmt":"2023-05-21T22:12:28","slug":"plots-in-latex","status":"publish","type":"post","link":"https:\/\/www.scijournal.org\/articles\/plots-in-latex","title":{"rendered":"How to Create Plots in Latex"},"content":{"rendered":"\n<p>One of the more advanced functions offers is the ability to create lots in Latex. You can create a variety of different plots in LaTeX depending on your needs. This includes 2D plots such as line plots and scatters plots and 3D plots such as contour plots and parametric plots.&nbsp;<\/p>\n\n\n\n<p>Let\u2019s look at how to create different plots in LaTeX.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_67_1 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e1ea296e50c\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e1ea296e50c\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#How_Does_you_create_Plots_in_Latex\" title=\"How Does you create Plots in Latex?\">How Does you create Plots in Latex?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Why_Figures_Take_Long_to_Compile\" title=\"Why Figures Take Long to Compile\">Why Figures Take Long to Compile<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Creating_a_Simple_Plots_in_Latex\" title=\"Creating a Simple Plots in Latex\">Creating a Simple Plots in Latex<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Creating_Simple_2D_Plots_in_Latex\" title=\"Creating Simple 2D Plots in Latex\">Creating Simple 2D Plots in Latex<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Creating_a_Plot_from_Data\" title=\"Creating a Plot from Data\">Creating a Plot from Data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Creating_Scatter_Plots_in_LaTeX\" title=\"Creating Scatter Plots in LaTeX\">Creating Scatter Plots in LaTeX<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Creating_3D_Plots_in_LaTeX\" title=\"Creating 3D Plots in LaTeX\">Creating 3D Plots in LaTeX<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Creating_Contour_Plots_in_LaTeX\" title=\"Creating Contour Plots in LaTeX\">Creating Contour Plots in LaTeX<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Final_Thoughts\" title=\"Final Thoughts\">Final Thoughts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Frequently_Asked_Questions\" title=\"Frequently Asked Questions&nbsp;\">Frequently Asked Questions&nbsp;<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Q1_Can_You_Plot_in_LaTeX\" title=\"Q1. Can You Plot in LaTeX?\">Q1. Can You Plot in LaTeX?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Q2_How_Do_You_Plot_a_Line_in_LaTeX\" title=\"Q2. How Do You Plot a Line in LaTeX?\">Q2. How Do You Plot a Line in LaTeX?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Q3_How_Do_You_Make_a_Scatter_Plot_in_LaTeX\" title=\"Q3. How Do You Make a Scatter Plot in LaTeX?\">Q3. How Do You Make a Scatter Plot in LaTeX?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\/#Further_Reading\" title=\"Further Reading\">Further Reading<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"how-does-you-create-plots-in-latex\"><span class=\"ez-toc-section\" id=\"How_Does_you_create_Plots_in_Latex\"><\/span>How Does you create Plots in Latex?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You may be wondering how a document processing system such as LaTeX is capable of producing 2D and 3D plots. This is made possible thanks to the <em>pgfplots<\/em> package. This package is based on the tool <em>TikZ<\/em>, which is useful for creating scientific or technical graphics.&nbsp;<\/p>\n\n\n\n<p>Users simply need to add their data or formulas into LaTeX and <em>pgfplots<\/em> turns them into visual representations.<\/p>\n\n\n\n<p>If you wish to use <em>pgfplots<\/em> in a LaTeX document to create plots in Latex, you will need to include it in your document\u2019s preamble with the command <em>\\usepackage{pgfplots}<\/em>. It is also possible to change how <em>pgfplots<\/em> behaves to create custom sized plots. For example, using the code: <em>\\pgfplotsset{width=8cm}<\/em>, we can set the size of the plotted figure as 8cm.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-figures-take-long-to-compile\"><span class=\"ez-toc-section\" id=\"Why_Figures_Take_Long_to_Compile\"><\/span>Why Figures Take Long to Compile<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you have been using LaTeX to create plots in Latex for a while, you may be used to your documents being compiled within a matter of seconds. However, documents containing plots often take much longer to compile. This is because LaTeX wasn\u2019t originally meant for creating plots.<\/p>\n\n\n\n<p>When TeX was originally conceived, the idea was to create graphics separately using programs such as MetaPost and insert them into LaTeX documents. However, packages such as <em>pdfTeX<\/em> introduced the ability to create graphics directly in LaTeX. Following this, more advanced graphics packages including <em>pgfplots<\/em> and <em>TikZ<\/em> were created.<\/p>\n\n\n\n<p>These new packages are capable of creating plots in LaTeX using high-level commands. However, these commands must still be turned back into low-level commands for LaTeX\u2019s engine to process them.&nbsp;<\/p>\n\n\n\n<p>This means even one high-level command could require multiple low-level engine commands to be executed. All this results in graphics taking a fair amount of time to be rendered to create plots in LaTeX.<\/p>\n\n\n\n<p>One possible workaround for long rendering times is to export your figures as PDF files and then add them to your document. You can do this by inserting the following code into your document preamble:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\usepgfplotslibrary{external}\n\\tikzexternalize\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-a-simple-plots-in-latex\"><span class=\"ez-toc-section\" id=\"Creating_a_Simple_Plots_in_Latex\"><\/span>Creating a Simple Plots in Latex<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now that we have discussed the background to creating plots in LaTeX, let\u2019s try creating a basic 2D plot alongside a basic 3D one.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\documentclass{article}\n\\usepackage&#x5B;margin=0.25in]{geometry}\n\\usepackage{pgfplots}\n\\pgfplotsset{width=8cm,compat=1.9}\n \n\\usepgfplotslibrary{external}\n\\tikzexternalize\n \n\\begin{document}\n \n\\begin{tikzpicture}\n\\begin{axis}\n\\addplot&#x5B;color=blue]{exp(x)};\n\\end{axis}\n\\end{tikzpicture}\n \n\\hskip 8pt\n \n\\begin{tikzpicture}\n\\begin{axis}\n\\addplot3&#x5B;\n    surf,\n]\n{exp(y^2-x^2)*x};\n\\end{axis}\n\\end{tikzpicture}\n\\end{document}\n\n<\/pre><\/div>\n\n\n<p>The above code produces a 2D line plot alongside a 3D plot..&nbsp;<\/p>\n\n\n\n<p>We first started by creating a <em>tikzpicture<\/em> environment, as any <em>pgfplots<\/em> must be located inside this environment. We then used the commands <em>\\begin{axis}<\/em>, and <em>\\end{axis}<\/em> to set linear scaling for our plot.&nbsp;<\/p>\n\n\n\n<p>If we wanted a log scale for <em>x <\/em>and normal scale for <em>y<\/em> we could use the commands \\begin{semilogxaxis}, and \\end{semilogxaxis}. We will discuss more of these axes commands later in this guide.<\/p>\n\n\n\n<p>In the above code, we used<em> \\addplot[color=blue]{log(x)}<\/em> to set our plot color to blue.&nbsp;<\/p>\n\n\n\n<p>Notice how the <em>color<\/em> parameter is enclosed in square brackets. We can add additional plot options in these square brackets. Just remember to include them in your code syntax, even if you aren\u2019t using any additional options. The code also ends with a semicolon \u201c<em>;<\/em>\u201d.<\/p>\n\n\n\n<p>We then added a second plot next to the first one by declaring the new picture environment using<em>\\begin{tikzpicture}<\/em>. Above this command we added <em>\\hskip 8pt<\/em> to insert a blank space 8pt wide between our two plots. We then followed the same code as we did for the first plot.&nbsp;<\/p>\n\n\n\n<p>Using the code<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\addplot3&#x5B;\n    surf,\n]\n{exp(y^2-x^2)*x};\n\n<\/pre><\/div>\n\n\n<p>We added a plot for the expression <em>exp(y^2-x^2)*x<\/em>. The <em>addplot3<\/em> code informs LaTeX to create a 3-D plot, and the code <em>[surf]<\/em> specifies that it should be a surface plot for the aforementioned equation. This equation should always be enclosed using curly brackets <em>{&#8230;}<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-simple-2d-plots-in-latex\"><span class=\"ez-toc-section\" id=\"Creating_Simple_2D_Plots_in_Latex\"><\/span>Creating Simple 2D Plots in Latex<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the above example, we showed a 2D plot alongside a 3D one. Let\u2019s examine the process of creating a simple 2D plot in more detail.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\begin{tikzpicture}\n\\begin{axis}&#x5B;\n    axis lines = left,\n    xlabel = \\(x\\),\n    ylabel = {\\(f(x)\\)},\n]\n\\addplot &#x5B;\n    domain=-10:10, \n    samples=100, \n    color=blue,\n]\n{x^2 + 3x};\n\\addlegendentry{\\(x^2 + 3x\\)}\n \n\\addplot &#x5B;\n    domain=-10:10, \n    samples=100, \n    color=red,\n    ]\n    {x^2 + 3*x};\n\\addlegendentry{\\(x^2 + 3x\\)}\n \n\\end{axis}\n\\end{tikzpicture}\n\n<\/pre><\/div>\n\n\n<p>In the above code, we used the command <em>axis lines = left<\/em> to set our axis so that they are visible only on the bottom and left portion of our plot. Using the default <em>box<\/em> parameter here would have created an axes on the top and right hand sides as well.<\/p>\n\n\n\n<p>We also used the following code to label what the x-axis and y-axis on our plot mean.<\/p>\n\n\n\n<p><em>xlabel = \\(x\\)&nbsp;<\/em><\/p>\n\n\n\n<p><em>ylabel = {\\(f(x)\\)}&nbsp;<\/em><\/p>\n\n\n\n<p>Note that the y-axis label is enclosed in curly brackets <em>{&#8230;}<\/em> as this informs <em>pgfplots<\/em> about grouping the text inside. If we wanted to use complex labels for the x-axis, we could enclose its code in curly brackets as well.<\/p>\n\n\n\n<p>We then used <em>\\addplot <\/em>to add our first plot. Note the inclusion of the parameters&nbsp;&nbsp;<\/p>\n\n\n\n<p>domain=-10:10,&nbsp;<\/p>\n\n\n\n<p>samples=100,&nbsp;<\/p>\n\n\n\n<p>color=blue,<\/p>\n\n\n\n<p>The <em>color<\/em> parameter sets the color of the plotted line, while the <em>domain <\/em>&nbsp;and <em>samples<\/em> parameter describes the x-value range and the number of points in the domain\u2019s interval. You can set the <em>samples<\/em> parameter much higher than 100 to produce a smoother looking graph. However, such graphs take more time to render.<\/p>\n\n\n\n<p>Finally, we used the code <em>\\addlegendentry{\\(x^2 + 3x\\)} <\/em>to add our equation label to the legend. Then to add the second plot, we simply used <em>\\addplot<\/em> and the same steps again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-a-plot-from-data\"><span class=\"ez-toc-section\" id=\"Creating_a_Plot_from_Data\"><\/span>Creating a Plot from Data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In some cases, you may wish to create plots in LaTeX using data rather than equations. This is possible in <em>pgfplots<\/em>, and we demonstrate this using the following example.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\begin{tikzpicture}\n\\begin{axis}&#x5B;\n    title={Acceleration vs Time},\n    xlabel={Time &#x5B;\\textseconds]},\n    ylabel={Acceleration},\n    xmin=0, xmax=100,\n    ymin=0, ymax=120,\n    xtick={0,20,40,60,80,100},\n    ytick={0,20,40,60,80,100,120},\n    legend pos=north west,\n    ymajorgrids=true,\n    grid style=dashed,\n]\n \n\\addplot&#x5B;\n    color=red,\n    mark=square,\n    ]\n    coordinates {\n    (0,30)(10,31)(20,28)(30,42)(40,51)(60,57)(80,52)(100,32)\n    };\n    \\legend{Acceleration}\n    \n\\end{axis}\n\\end{tikzpicture}\n\n<\/pre><\/div>\n\n\n<p>In the above code, <em>title={Acceleration vs Time}<\/em> sets the graph title as <em>Acceleration vs Time<\/em>. We then used <em>xmin=0, xmax=100, ymin=0, ymax=120<\/em> to set the upper and lower bounds of both the <em>x<\/em> and <em>y <\/em>axes.<\/p>\n\n\n\n<p>We also used the code <em>xtick={0,20,40,60,80,100}, ytick={0,20,40,60,80,100,120} <\/em>to set where the interval marks are placed. If we did not specify this, the interval marks would be set automatically.<\/p>\n\n\n\n<p>We then used the code <em>legend pos=north west<\/em> to position the legend box near the top-left of the plot.&nbsp; The code <em>ymajorgrids=true<\/em> disabled the grid lines on the y-axis. If we wanted to disable gridlines for the x-axis, we could have used <em>xmajorgrids=true<\/em>.<\/p>\n\n\n\n<p>The code <em>grid style=dashed<\/em> informs LaTeX to use dashed grid lines in the graph. We then used the command <em>mark=square<\/em> to add a square marker on each point in the plot. Then inputted our coordinates using the code&nbsp;<\/p>\n\n\n\n<p><em>coordinates {<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;(0,30)(10,31)(20,28)(30,42)(40,51)(60,57)(80,52)(100,32)<\/em><\/p>\n\n\n\n<p><em>&nbsp;&nbsp;&nbsp;&nbsp;};<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-scatter-plots-in-latex\"><span class=\"ez-toc-section\" id=\"Creating_Scatter_Plots_in_LaTeX\"><\/span>Creating Scatter Plots in LaTeX<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Scatter plots in latex are useful for showing large sets of data visually. In this example, we will be importing data from a separate file called <em>scatterdata.dat<\/em>.&nbsp; We use the following code to create our scatter plot:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\begin{tikzpicture}\n\\begin{axis}&#x5B;\n    enlargelimits=false,\n]\n\\addplot+&#x5B;\n    only marks,\n    scatter,\n    mark=diamond*,\n    mark size=2.4pt]\ntable&#x5B;meta=ma]\n{scatterdata.dat};\n\\end{axis}\n\\end{tikzpicture}\n\n<\/pre><\/div>\n\n\n<p>In the above code, we used <em>enlarge limits=false <\/em>to shrink our axes. This helped align them with the data points at the edge of the plot.<\/p>\n\n\n\n<p>We used the code <em>only marks<\/em> to add a mark to each of our points. The code <em>scatter<\/em> specifies the type of plot. We then used <em>mark=diamond*<\/em> to inform LaTeX to use a diamond-shaped marker for our points. Next, we set the size for the mark using <em>mark size=2.4pt<\/em>.<\/p>\n\n\n\n<p>The code <em>table[meta=ma]{scatterdata.dat};<\/em> tells LaTeX to draw the scatter plot data from the file <em>scatterdata.dat<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-3d-plots-in-latex\"><span class=\"ez-toc-section\" id=\"Creating_3D_Plots_in_LaTeX\"><\/span>Creating 3D Plots in LaTeX<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Creating 3D plots in LaTeX is made possible using <em>pgfplots<\/em>. Let\u2019s plot a mathematical expression as an example.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\begin{tikzpicture}\n\\begin{axis}&#x5B;\n    title=Example using the mesh parameter,\n    hide axis,\n    colormap\/violet,\n]\n\\addplot3&#x5B;\n    mesh,\n    samples=60,\n    domain=-8:8,\n]\n{sin(deg(sqrt(x^3+y^3)))\/sqrt(x^3+y^3)};\n\\addlegendentry{\\(\\frac{sin(r)}{r}\\)}\n\\end{axis}\n\\end{tikzpicture}\n\n<\/pre><\/div>\n\n\n<p>In the above code, we used the command <em>hide axis<\/em> to keep the axis hidden in the plot.&nbsp;<\/p>\n\n\n\n<p>We also used the code <em>colormap\/violet<\/em> to set the color scheme for the plot. Some other color schemes are <em>blackwhite<\/em>, <em>bluered<\/em>, and <em>greenyellow<\/em>.<\/p>\n\n\n\n<p>The code <em>mesh<\/em> informs LaTeX to create a mesh-style 3D plot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-contour-plots-in-latex\"><span class=\"ez-toc-section\" id=\"Creating_Contour_Plots_in_LaTeX\"><\/span>Creating Contour Plots in LaTeX<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LaTeX also lets you create contour plots using <em>pgfplots<\/em>. You can plot your contour points using commands. However, this data must still be pre-calculated using an external program. We demonstrate how to create contour plots in the following example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\\begin{tikzpicture}\n\\begin{axis}\n&#x5B;\n    title={Contour plot, view from top},\n    view={0}{90}\n]\n\\addplot3&#x5B;\n    contour gnuplot={levels={0.9, 0.5, 0.3, -0.1}}\n]\n{sin(deg(sqrt(x^3+y^3)))\/sqrt(x^3+y^3)};\n\\end{axis}\n\\end{tikzpicture}\n\n<\/pre><\/div>\n\n\n<p>In the above code, we used <em>view={0}{90}<\/em> to set the view for our plot. The first value \u201c0\u201d describes the degrees of rotation around the z-axis, while the second value \u201c90\u201d describes the degrees of rotation around the x-axis. When combined, a 0 degree rotation about the z-axis and a 90 degree rotation around the x-axis produces a top-down view.<\/p>\n\n\n\n<p>We also used the code <em>contour gnuplot={levels={0.9, 0.5, 0.3, -0.1}}<\/em>. This code informs LaTeX to use <em>gnuplot<\/em> for computing our contour lines. The numbers in this code describe the <em>levels<\/em> or elevation levels for the contour lines we are plotting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"final-thoughts\"><span class=\"ez-toc-section\" id=\"Final_Thoughts\"><\/span>Final Thoughts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>As you can see, you can create many different types of 2D and 3D plots in LaTeX. As mentioned earlier, you have plenty of customizations for your plots, such as colors, markers, axes, and interval size.&nbsp;<\/p>\n\n\n\n<p>So try experimenting with the code used in the examples above and spruce up your next LaTeX document with some professional-looking plots.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questions\"><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Some frequently asked questions related to plots in LaTeX are shown below.<\/p>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1630926113014\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"Q1_Can_You_Plot_in_LaTeX\"><\/span>Q1. Can You Plot in LaTeX?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>It is possible to create plots in LaTeX. However, this requires you to use the packages <em>TikZ <\/em>and <em>pgfplots<\/em>. Once these have been loaded, you can create 2D and 3D.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1630926120323\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"Q2_How_Do_You_Plot_a_Line_in_LaTeX\"><\/span>Q2. How Do You Plot a Line in LaTeX?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can plot a simple line in LaTeX by first using the following code format:<br \/>\\begin{tikzpicture}<br \/>\\begin{axis}[<br \/>xlabel=YOUR XAXIS LABEL,<br \/>ylabel=YOUR YAXIS LABEL,<br \/>width=10cm,height=7cm,<br \/>legend style={at={(0.0,.91)},anchor=west}<br \/>]<br \/>\\addplot[color=red,mark=x] coordinates {<br \/>(1, 5)<br \/>(2, 6)<br \/>(3, 7)<br \/>(4, 8)<br \/>(5, 9)<br \/>(6, 10)<br \/>};<br \/>\\legend{Simple Line Plot}<br \/>\\end{axis}<br \/>\\end{tikzpicture}<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1630926187106\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"Q3_How_Do_You_Make_a_Scatter_Plot_in_LaTeX\"><\/span>Q3. How Do You Make a Scatter Plot in LaTeX?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can create a scatter plot in LaTeX using the following code format:<br \/>\\begin{tikzpicture} <br \/>\\begin{axis}[ enlargelimits=false, ] <br \/>\\addplot+[ only marks, scatter, mark=diamond*, mark size=2.4pt] table[meta=ma] {scatterdata.dat}; <br \/>\\end{axis} <br \/>\\end{tikzpicture}<br \/>In the above example, we imported data for the scatter plot from the file <em>scatterdata.dat<\/em><\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: latex; title: ; notranslate\" title=\"\">\n\n<\/pre><\/div>\n\n\n<h2 class=\"gb-headline gb-headline-c8ee9dc0 gb-headline-text\"><span class=\"ez-toc-section\" id=\"Further_Reading\"><\/span><strong>Further Reading<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>LaTex Tutorial<\/strong><\/p>\n\n\n\n<ol><li><a href=\"https:\/\/www.scijournal.org\/articles\/pros-and-cons-of-using-latex\">27 Pros and Cons of Using LaTex for Scientific Writing<\/a> <\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-document\">6 easy steps to create your first Latex document examples<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/circuit-diagrams-in-latex\">How to add circuit diagrams in Latex<\/a> <\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-font\">How to change Latex font and font size<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-table-of-contents\">How to create a Latex table of contents<\/a> <\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/footnotes-in-latex\">How to create footnotes in LaTeX and how to refer to them, using the builtin commands<\/a> <\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/glossaries-in-latex\">How to create Glossaries in LaTeX<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/symbols-in-latex\">How to create symbols in LaTeX \u2013 commands for Latex greek alphabet<\/a>\u00a0 <\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-tables\">How to create tables in LaTeX \u2013 rows, columns, pages and landscape tables<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/graphs-in-latex\">How to drawing graphs in Latex \u2013 vector graphics with tikz<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/source-code-in-latex\">How to highlight source code in LaTeX<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/image-in-latex\">How to insert an image in LaTeX \u2013 Managing Latex figure and picture<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-bullet-points\">How to Itemize and Number List \u2013 Adding Latex Bullet Points<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/hyperlinks-in-latex\">How to make hyperlink in latex \u2013 Clickable links<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/reference-in-latex\">How to reference in Latex \u2013 5 steps to bibliography with Bibtex<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-packages\">How to use Latex Packages with examples<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-paragraphs\">How to use LaTeX paragraphs and sections<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-installation-guide\">LaTeX Installation Guide \u2013 Easy to follow steps to install LaTex<\/a><\/li><li><a href=\"https:\/\/www.scijournal.org\/articles\/latex-equations-and-math\">Learn to typeset and align Latex equations and math<\/a><\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>One of the more advanced functions offers is the ability to create lots in Latex. You can create a variety of different plots in LaTeX depending on your needs. This includes 2D plots such as line plots and scatters plots and 3D plots such as contour plots and parametric plots.&nbsp; Let\u2019s look at how to &#8230; <a title=\"How to Create Plots in Latex\" class=\"read-more\" href=\"https:\/\/www.scijournal.org\/articles\/plots-in-latex\" aria-label=\"Read more about How to Create Plots in Latex\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":335,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/posts\/334"}],"collection":[{"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/comments?post=334"}],"version-history":[{"count":8,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/posts\/334\/revisions"}],"predecessor-version":[{"id":5582,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/posts\/334\/revisions\/5582"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/media\/335"}],"wp:attachment":[{"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/media?parent=334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/categories?post=334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scijournal.org\/articles\/wp-json\/wp\/v2\/tags?post=334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}