Change the font size of title in Matplotlib

In Python, there are a lot of libraries that are used for data visualization. One of the libraries is the Matplotlib library. The Matplotlib library is a very good library when it comes to data visualisation in python. With the help of this library, many types of graphs and visual representations of the data can be made in Python.

While plotting graphs with the help of this library, it is always necessary to label everything on the graph and give the graph a proper title. This helps in understanding all the visualizations and graphs more efficiently.

In this tutorial, we will see how to add and modify the font of the title in Matplotlib library.

Use the matplotlib.pyplot.title() Function

The matplotlib.pyplot.title() function of the matplotlib library is used to assign the title to a given visualization or graph. This function has various parameters such as:

  • label (str) – This parameter is used to defines the text that is used for the title of the visualization.

  • fontdict (dict) – This parameter is a dictionary that is used to control the appearance of the text of the title. The default fontdict is:

  • loc (str) – This parameter defines the place of the title. There are three places for the title, left, right, and centre. The default value of this parameter is centre. This is an optional parameter i.e, it is not necessary to define it in every program.

Now let’s see how to use the matplotlib.pyplot.title() function with help of some examples:

Example 1:

Output:

  • In the above code, a straight line is plotted with the help of the formula y=mx+c. Note that to define the x coordinate, the linspace function of the NumPy module is used. The linspace() function helps in creating a random numerical sequence that are evenly spaced.
  • Also, note that the font sizes of the x and y label can also modify as per requirement

Example 2:

Output:

  • Note that in the given code, all the different components are named with the of labels parameter of the pie function of the matplotlib library which is defined in the starting itself.
  • Finally, the title is defined with a proper font size with centre as its default loc.

Related Posts

  • Python add commas to number
    11 September

    Python add commas to number

    Table of ContentsUsing the format() function to add commas to numbers in PythonUsing the fstrings to add commas to numbers in PythonUsing the regular expressions to add commas to numbers in PythonUsing the locale module to add commas to numbers in Python Python allows us to format values to get the final result in our […]

  • 11 September

    RSA Encryption and Decryption in Java

    Table of ContentsIntroductionGenerate RSA key pairEncrypt a random textDecrypt the random textConclusion Introduction RSA is a short form for Rivest, Shamir, and Adleman, are the people who first publicly described it in 1977. It is an algorithm for asymmetric cryptography which involves the use of two keys. A public key, which can be known to […]

  • 10 September

    How to remove element from Arraylist in java while iterating

    Table of ContentsIntroductionUsing Collection’s removeIf() methodUsing ListIterator classUsing removeAll() methodUsing Java 8 Stream to filter List itemsConclusion Introduction In this tutorial, you will learn how to remove element from Arraylist in java while iterating using different implementations provided by Java. It is necessary to understand the right way to remove items from a List because […]

  • Watch New Release Movies Online Free Without Signing Up
    10 September

    Watch New Release Movies Online Free Without Signing Up: Top 22 Websites

    Table of ContentsWatch New Release Movies Online Free Without Signing UpWatch New Release Movies Online Free Without Signing Up: Best Websites123MoviesFMoviesWatchFreeYes MoviesYifi MoviesWatch Movie StreamSolar MoviesPut LockerSony CrackleMovies JoyYo MoviesPopcorn FlixCracklePluto TVSome other Platforms to Watch New Release Movies Online Free Without Signing Up It is Saturday night again, and are you tired of signing […]

  • Free movie apps for android
    08 September

    22 Best Free Movie Apps For Android

    Table of ContentsThe Most Promising Free Movie Apps for AndroidPopcornflixSony CrackleFreeFlix HQVuduTubi TVFilm RiseUKMovNowCrunchyrollCyberflix TVYidioPluto TVTea TVPlexMovies AnywhereOld MoviesCinema HDVideoMixKodiSnagfilmsIMDB OriginalsFree Movie Tube App for AndroidMegabox HDFrequently Asked Questions About Free Movie Apps for AndroidDo there exist free movie apps for Android?Which are the best free movie apps for Android?Is it safe to use the […]

  • Free live tv streaming sites
    08 September

    Best Free Live TV Streaming Sites in 2021

    Table of ContentsBest Free Live TV Streaming Sites in 2021Stream2WatchTVPlayerUSTVGO123TVPluto TVUStreamXumoOK Live TVAiry TVPlex Live TVDistro TVCrackstreamsSquid TVFree TVMX PlayerTV CatchupTime4TVPeacock TVYupp TVSports SurgeFrequently Asked Questions About Free Live TV Streaming SitesIs watching free live tv streaming sites possible on Android/Firestick?What are the best free live TV streaming sites?Are the free live tv streaming sites […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.