Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 tell exact difference between xlim() and xticks() function ift38375 Silly Frenchman Posts: 24 Threads: 14 Joined: Apr 2019 Reputation: 0 Likes received: 0 #1 Jul-11-2019, 01:11 AM I am confused in xlim() and xticks() function of Matplotlib.pyplot. are both same or different ? Please explain with simple graph example.. scidam Posts: 509 Threads: 1 Joined: Mar 2018 Reputation: 69 Likes received: 69 #2 Jul-11-2019, 02:10 AM They are different. The first (`plt.xlim()`) returns range for x-axis values of the current axes-instance, the second returns array of xtick labels (where labels will be placed) within the interval returned by `xlim`. Look at the following example: ```import matplotlib.pyplot as plt ax = plt.gca() # returns current axes (creates if needed) ax.get_xlim() # now this is equivalent to plt.xlim(), plt.xlim() returns xlims for the current axes `````````Output: (0.0, 1.0)```````ax.get_xticks() # returns where ticks be located. plt.xticks() returns xticks for the current axes```Output:array([0. , 0.2, 0.4, 0.6, 0.8, 1. ])``Lets change xlims, e.g. `ax.set_xlim(5, 9) # the same as plt.xlim(5, 9) (we are still working with the current axes)```Output:(5, 9)```plt.xticks()```````Output:(array([5. , 5.5, 6. , 6.5, 7. , 7.5, 8. , 8.5, 9. ]), )```````ax.get_xticks()```Output:array([5. , 5.5, 6. , 6.5, 7. , 7.5, 8. , 8.5, 9. ])```plt.xlim()```Output:(5.0, 9.0)`` snippsat and ThomasL like this post ift38375 Silly Frenchman Posts: 24 Threads: 14 Joined: Apr 2019 Reputation: 0 Likes received: 0 #3 Jul-11-2019, 03:27 PM (Jul-11-2019, 02:10 AM)scidam Wrote: They are different. The first (`plt.xlim()`) returns range for x-axis values of the current axes-instance, the second returns array of xtick labels (where labels will be placed) within the interval returned by `xlim`. Look at the following example: ```import matplotlib.pyplot as plt ax = plt.gca() # returns current axes (creates if needed) ax.get_xlim() # now this is equivalent to plt.xlim(), plt.xlim() returns xlims for the current axes `````````Output: (0.0, 1.0)```````ax.get_xticks() # returns where ticks be located. plt.xticks() returns xticks for the current axes```Output:array([0. , 0.2, 0.4, 0.6, 0.8, 1. ])``Lets change xlims, e.g. `ax.set_xlim(5, 9) # the same as plt.xlim(5, 9) (we are still working with the current axes)```Output:(5, 9)```plt.xticks()```````Output:(array([5. , 5.5, 6. , 6.5, 7. , 7.5, 8. , 8.5, 9. ]), )```````ax.get_xticks()```Output:array([5. , 5.5, 6. , 6.5, 7. , 7.5, 8. , 8.5, 9. ])```plt.xlim()```Output:(5.0, 9.0)`` can we use values with Negative X-axis/Y-axis ? scidam Posts: 509 Threads: 1 Joined: Mar 2018 Reputation: 69 Likes received: 69 #4 Jul-12-2019, 12:04 AM (Jul-11-2019, 03:27 PM)ift38375 Wrote: can we use values with Negative X-axis/Y-axis ? Yes, you can use negative values in these functions. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post How to find difference between two timestamp index python_newbie09 3 143 Aug-01-2019, 10:24 AM Last Post: python_newbie09 xticks mcgrim 5 890 Jun-09-2019, 09:00 PM Last Post: mcgrim Getting the difference between two times in a Data Frame soulkid555 4 353 Mar-21-2019, 11:22 AM Last Post: perfringo finding exact and similar matches from pandas dataframe? PrateekG 0 813 Apr-22-2018, 01:22 PM Last Post: PrateekG What is the difference between parenthesis and no parenthesis in head and tail? kulimer 7 2,324 May-14-2017, 11:53 PM Last Post: volcano63

Forum Jump:

Users browsing this thread: 1 Guest(s)