banner



How To Change Number Of Ticks In Matplotli


You can use the following syntax to modify the number of ticks on each centrality in Matplotlib:

                          #specify number of ticks on x-axis              plt.locator_params(axis='x', nbins=iv)              #specify number of ticks on y-centrality              plt.locator_params(axis='y', nbins=2)                      

The nbins argument specifies how many ticks to display on each axis.

The following examples show how to apply this syntax in practice.

Example 1: Specify Number of Ticks on Both Axes

The post-obit code shows how to specify the number of ticks on both axes in a plot:

                                                            import                  matplotlib.pyplot                  equally                  plt                                #define data                x = [1, two, 3, 4] y = [vii, thirteen, 24, 22]                #create plot                plt.plot(x, y, color='red')                  #specify number of ticks on axes                  plt.locator_params(axis='x', nbins=4) plt.locator_params(axis='y', nbins=2)                                                    

Instance two: Specify Number of Ticks on 10-Axis Only

The post-obit code shows how to specify the number of ticks only on the x-centrality:

                                                            import                  matplotlib.pyplot                  as                  plt                                #define data                x = [1, 2, three, iv] y = [7, thirteen, 24, 22]                #create plot                plt.plot(10, y, color='red')                  #specify number of ticks on ten-axis                  plt.locator_params(axis='ten', nbins=ii)                                                    

Example three: Specify Number of Ticks on Y-Axis Only

The following code shows how to specify the number of ticks but on the y-axis:

                                                            import                  matplotlib.pyplot                  every bit                  plt                                #define data                x = [one, ii, 3, 4] y = [7, 13, 24, 22]                #create plot                plt.plot(10, y, colour='red')                  #specify number of ticks on y-axis                  plt.locator_params(axis='y', nbins=2)                                    

Change number of ticks in Matplotlib

Boosted Resource

How to Remove Ticks from Matplotlib Plots
How to Fix Tick Labels Font Size in Matplotlib
How to Set X-Axis Values in Matplotlib
How to Set Axis Ranges in Matplotlib

Source: https://www.statology.org/matplotlib-number-of-ticks/

Posted by: grimexpearre.blogspot.com

0 Response to "How To Change Number Of Ticks In Matplotli"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel