{"id":3491,"date":"2025-01-31T08:58:10","date_gmt":"2025-01-31T08:58:10","guid":{"rendered":"https:\/\/thumbtube.com\/blog\/?p=3491"},"modified":"2025-01-31T09:41:58","modified_gmt":"2025-01-31T09:41:58","slug":"how-to-draw-a-graph-in-manim","status":"publish","type":"post","link":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/","title":{"rendered":"How to Draw a Graph in Manim?"},"content":{"rendered":"<p>Manim, short for Mathematical Animation Engine, is a powerful Python library used to create stunning animations, particularly for mathematical and educational content. Among its wide range of capabilities is the ability to draw and animate graphs, which makes it an excellent tool for visualizing mathematical functions. This guide walks you through the process of drawing a graph in Manim, explaining the essential components and steps involved.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3492\" src=\"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/setting-up-manim-scaled.jpg\" alt=\"Setting Up Manim\" width=\"2560\" height=\"1707\" srcset=\"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/setting-up-manim-scaled.jpg 2560w, https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/setting-up-manim-300x200.jpg 300w, https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/setting-up-manim-1024x683.jpg 1024w, https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/setting-up-manim-768x512.jpg 768w, https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/setting-up-manim-1536x1024.jpg 1536w, https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/setting-up-manim-2048x1365.jpg 2048w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><\/p>\n<h2>Setting Up Manim<\/h2>\n<p>Before you can draw a graph, you need to set up Manim on your system. Start by installing Manim through pip by running the command pip install manim. Ensure that your Python environment is ready and supports all necessary dependencies. Once installed, you can test your setup by running a basic Manim script.<\/p>\n<p>To work with graphs in Manim, it is essential to import the relevant modules. Typically, this involves importing Scene and Axes or NumberPlane from manim.<\/p>\n<h2>Creating a Coordinate System<\/h2>\n<p>Graphs in Manim are drawn within a coordinate system, which can be created using the Axes or NumberPlane classes. The Axes class is ideal for creating standard x-y coordinate systems, while NumberPlane provides a grid-like structure.<\/p>\n<p>To create a coordinate system, initialize an Axes object with parameters such as axis ranges, label sizes, and colors. For example:<\/p>\n<p>from manim import *<\/p>\n<p>class GraphScene(Scene):<br \/>\ndef construct(self):<br \/>\naxes = Axes(<br \/>\nx_range=[-5, 5, 1],<br \/>\ny_range=[-5, 5, 1],<br \/>\naxis_config={&#8220;include_numbers&#8221;: True},<br \/>\n)<br \/>\nself.play(Create(axes))<\/p>\n<p>This script sets up a coordinate system with x and y ranges from -5 to 5, including numbered labels.<\/p>\n<h2>Plotting a Graph<\/h2>\n<p>To plot a graph, you need a mathematical function and an axes object. Manim provides the plot method in the Axes class to generate graphs from Python functions. Define the function you want to plot and use plot to create the graph.<\/p>\n<p>For instance, to plot :<\/p>\n<p>graph = axes.plot(lambda x: x**2, color=BLUE)<br \/>\nself.play(Create(graph))<\/p>\n<p>The lambda x: x**2 defines the function , and Create(graph) animates its appearance.<\/p>\n<h2>Adding Labels and Annotations<\/h2>\n<p>Manim allows you to add labels, titles, and other annotations to your graphs for better understanding. Use methods like add_labels or plot_label to include these elements.<\/p>\n<p>For example:<\/p>\n<p>graph_label = axes.get_graph_label(graph, label=&#8221;x^2&#8243;)<br \/>\nself.play(Write(graph_label))<\/p>\n<p>This snippet adds a label &#8220;x^2&#8221; to the graph.<\/p>\n<h2>Customizing Graph Appearance<\/h2>\n<p>Manim provides flexibility in styling your graph. You can change the graph\u2019s color, stroke width, and more by passing parameters to the plot method. For instance:<\/p>\n<p>graph = axes.plot(lambda x: x**2, color=RED, stroke_width=4)<\/p>\n<p>This creates a bold red graph for better visibility.<\/p>\n<h2>Rendering the Animation<\/h2>\n<p>After constructing your graph and animations, render the scene using the Manim CLI. Save your script in a .py file and run it using:<\/p>\n<p>manim -pql your_script_name.py GraphScene<\/p>\n<p>The -pql flag ensures that the output is of high quality and opens automatically for preview.<\/p>\n<p>Drawing a graph in Manim involves setting up a coordinate system, plotting the desired function, and customizing the graph\u2019s appearance. With its robust features and flexibility, Manim makes it easy to create visually appealing and informative graph animations. Experiment with different functions and styles to make the most of this powerful tool.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Manim, short for Mathematical Animation Engine, is a powerful Python library used to create stunning &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Draw a Graph in Manim?\" class=\"read-more button\" href=\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#more-3491\" aria-label=\"Read more about How to Draw a Graph in Manim?\">Read More<\/a><\/p>\n","protected":false},"author":45,"featured_media":3493,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[413,412,411],"class_list":["post-3491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guides","tag-drawing-a-graph","tag-graphic-design","tag-manim","infinite-scroll-item","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-25","no-featured-image-padding"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Draw a Graph in Manim? - ThumbTube<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Draw a Graph in Manim? - ThumbTube\" \/>\n<meta property=\"og:description\" content=\"Manim, short for Mathematical Animation Engine, is a powerful Python library used to create stunning ... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/\" \/>\n<meta property=\"og:site_name\" content=\"ThumbTube\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-31T08:58:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-31T09:41:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/how-to-draw-a-graph-in-manim.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Antonia Zivcic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Antonia Zivcic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/\",\"url\":\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/\",\"name\":\"How to Draw a Graph in Manim? - ThumbTube\",\"isPartOf\":{\"@id\":\"https:\/\/thumbtube.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/how-to-draw-a-graph-in-manim.jpg\",\"datePublished\":\"2025-01-31T08:58:10+00:00\",\"dateModified\":\"2025-01-31T09:41:58+00:00\",\"author\":{\"@id\":\"https:\/\/thumbtube.com\/blog\/#\/schema\/person\/a23e8065398888bc3d8d601286c9723e\"},\"breadcrumb\":{\"@id\":\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#primaryimage\",\"url\":\"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/how-to-draw-a-graph-in-manim.jpg\",\"contentUrl\":\"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/how-to-draw-a-graph-in-manim.jpg\",\"width\":1200,\"height\":675,\"caption\":\"How to Draw a Graph in Manim?\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/thumbtube.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Draw a Graph in Manim?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/thumbtube.com\/blog\/#website\",\"url\":\"https:\/\/thumbtube.com\/blog\/\",\"name\":\"ThumbTube\",\"description\":\"Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/thumbtube.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/thumbtube.com\/blog\/#\/schema\/person\/a23e8065398888bc3d8d601286c9723e\",\"name\":\"Antonia Zivcic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/thumbtube.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ade15f696bff4a97edb88152c94dce22?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ade15f696bff4a97edb88152c94dce22?s=96&d=mm&r=g\",\"caption\":\"Antonia Zivcic\"},\"description\":\"I'm Antonia, a copywriter with over five years of experience in the industry. I find joy in exploring a wide array of topics through my writing. It's my passion to create engaging and compelling content that resonates with readers.\",\"url\":\"https:\/\/thumbtube.com\/blog\/author\/antoniaz\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Draw a Graph in Manim? - ThumbTube","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/","og_locale":"en_US","og_type":"article","og_title":"How to Draw a Graph in Manim? - ThumbTube","og_description":"Manim, short for Mathematical Animation Engine, is a powerful Python library used to create stunning ... Read More","og_url":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/","og_site_name":"ThumbTube","article_published_time":"2025-01-31T08:58:10+00:00","article_modified_time":"2025-01-31T09:41:58+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/how-to-draw-a-graph-in-manim.jpg","type":"image\/jpeg"}],"author":"Antonia Zivcic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Antonia Zivcic","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/","url":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/","name":"How to Draw a Graph in Manim? - ThumbTube","isPartOf":{"@id":"https:\/\/thumbtube.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#primaryimage"},"image":{"@id":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#primaryimage"},"thumbnailUrl":"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/how-to-draw-a-graph-in-manim.jpg","datePublished":"2025-01-31T08:58:10+00:00","dateModified":"2025-01-31T09:41:58+00:00","author":{"@id":"https:\/\/thumbtube.com\/blog\/#\/schema\/person\/a23e8065398888bc3d8d601286c9723e"},"breadcrumb":{"@id":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#primaryimage","url":"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/how-to-draw-a-graph-in-manim.jpg","contentUrl":"https:\/\/thumbtube.com\/blog\/wp-content\/uploads\/2025\/01\/how-to-draw-a-graph-in-manim.jpg","width":1200,"height":675,"caption":"How to Draw a Graph in Manim?"},{"@type":"BreadcrumbList","@id":"https:\/\/thumbtube.com\/blog\/how-to-draw-a-graph-in-manim\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thumbtube.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Draw a Graph in Manim?"}]},{"@type":"WebSite","@id":"https:\/\/thumbtube.com\/blog\/#website","url":"https:\/\/thumbtube.com\/blog\/","name":"ThumbTube","description":"Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thumbtube.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/thumbtube.com\/blog\/#\/schema\/person\/a23e8065398888bc3d8d601286c9723e","name":"Antonia Zivcic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thumbtube.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ade15f696bff4a97edb88152c94dce22?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ade15f696bff4a97edb88152c94dce22?s=96&d=mm&r=g","caption":"Antonia Zivcic"},"description":"I'm Antonia, a copywriter with over five years of experience in the industry. I find joy in exploring a wide array of topics through my writing. It's my passion to create engaging and compelling content that resonates with readers.","url":"https:\/\/thumbtube.com\/blog\/author\/antoniaz\/"}]}},"_links":{"self":[{"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/posts\/3491"}],"collection":[{"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/comments?post=3491"}],"version-history":[{"count":1,"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/posts\/3491\/revisions"}],"predecessor-version":[{"id":3494,"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/posts\/3491\/revisions\/3494"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/media\/3493"}],"wp:attachment":[{"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/media?parent=3491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/categories?post=3491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thumbtube.com\/blog\/wp-json\/wp\/v2\/tags?post=3491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}