0

Does anyone know how I can change the X-axis limits? I already tried using xlim property but it doesn't work

here is my code:

test = df.groupby(['Age','Salary']).count()['race'].unstack()
test.plot(kind='bar',subplots=True,sharex=False, figsize=(6,5), title="Age vs Income")
plt.show()

Figure1
Figure 1

as you may see on the image is not possible to view the x values since it has a lot of them, I looking to get something like this:

Figure2
Figure 2

also if anyone have an idea of how to removed the text that i highlighted with yellow it would be much appreciated.

This is an example of my df after group it by Age and Salary

Figure3

Figure 3

Ticherhaz FreePalestine
  • 2,738
  • 4
  • 20
  • 46

1 Answers1

0

I think what you want is to reduce the number of ticks. For this locator_params should help. For example you can use it like this:

test = df.groupby(['Age','Salary']).count()['race'].unstack()
test.plot(kind='bar',subplots=True,sharex=False, figsize=(6,5), title="Age vs Income")
plt.locator_params(axis="x", nbins=8)
plt.show() 
Julio Reckin
  • 146
  • 1
  • 10
  • it doesnt work, i tried but what i get is that now the x axis has just 8 number which are the first 8 numbers of my data (17,18,19...24), but the graph doesn't change, for example: now the last value which is 90 is represented by 24 – Ricardo Ernesto Oct 07 '20 at 01:55
  • Oh sorry I see, maybe here you can find a solution: https://stackoverflow.com/questions/6682784/reducing-number-of-plot-ticks – Julio Reckin Oct 07 '20 at 10:22
  • Try the answer here with 214 upvotes: https://stackoverflow.com/questions/12608788/changing-the-tick-frequency-on-x-or-y-axis-in-matplotlib/12608937 – Julio Reckin Oct 07 '20 at 10:49