Specifying values for my x-axis using the matplotlib.pyplot?
up vote
1
down vote
favorite
I am not able to specify values for my x-axis , using the matplotlib.pyplot
.
In some images the chart.xticks(years)
solves the problem , but it seems that when the set of x-axis values is too small , it uses default values like [0,1,2,...,N].
A case that works:
A case that does not works:
My code:
import matplotlib.pyplot as chart
from matplotlib import lines
# Settings
chart.title(file_name)
chart.xlabel('Years')
chart.ylabel('Committers/Contributions')
chart.ylim([0,highest_value + 100])
chart.xlim(first_year,2017)
# Values
committer_line = chart.plot(committers_dict.keys(),committers_dict.values(),'r',label='Committer')
contribution_line = chart.plot(contributions_dict.keys(),contributions_dict.values(),'b--',label='Contribution')
years = list(range(first_year,2017))
chart.xticks(years)
# Legend
chart.legend()
# Show/Save
chart.savefig(images_path + file_name.replace('.txt','-commiter-contribution.eps'), format='eps')
chart.show()
python matplotlib
add a comment |
up vote
1
down vote
favorite
I am not able to specify values for my x-axis , using the matplotlib.pyplot
.
In some images the chart.xticks(years)
solves the problem , but it seems that when the set of x-axis values is too small , it uses default values like [0,1,2,...,N].
A case that works:
A case that does not works:
My code:
import matplotlib.pyplot as chart
from matplotlib import lines
# Settings
chart.title(file_name)
chart.xlabel('Years')
chart.ylabel('Committers/Contributions')
chart.ylim([0,highest_value + 100])
chart.xlim(first_year,2017)
# Values
committer_line = chart.plot(committers_dict.keys(),committers_dict.values(),'r',label='Committer')
contribution_line = chart.plot(contributions_dict.keys(),contributions_dict.values(),'b--',label='Contribution')
years = list(range(first_year,2017))
chart.xticks(years)
# Legend
chart.legend()
# Show/Save
chart.savefig(images_path + file_name.replace('.txt','-commiter-contribution.eps'), format='eps')
chart.show()
python matplotlib
Note that it is not reverting to [0,1,2...N] as in the bottom right you can see +2.011e3 meaning it is actually plotting 2011,2012 and so on, so it is just a matter of how you are showing it.
– Alessandro
Mar 23 '16 at 18:07
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am not able to specify values for my x-axis , using the matplotlib.pyplot
.
In some images the chart.xticks(years)
solves the problem , but it seems that when the set of x-axis values is too small , it uses default values like [0,1,2,...,N].
A case that works:
A case that does not works:
My code:
import matplotlib.pyplot as chart
from matplotlib import lines
# Settings
chart.title(file_name)
chart.xlabel('Years')
chart.ylabel('Committers/Contributions')
chart.ylim([0,highest_value + 100])
chart.xlim(first_year,2017)
# Values
committer_line = chart.plot(committers_dict.keys(),committers_dict.values(),'r',label='Committer')
contribution_line = chart.plot(contributions_dict.keys(),contributions_dict.values(),'b--',label='Contribution')
years = list(range(first_year,2017))
chart.xticks(years)
# Legend
chart.legend()
# Show/Save
chart.savefig(images_path + file_name.replace('.txt','-commiter-contribution.eps'), format='eps')
chart.show()
python matplotlib
I am not able to specify values for my x-axis , using the matplotlib.pyplot
.
In some images the chart.xticks(years)
solves the problem , but it seems that when the set of x-axis values is too small , it uses default values like [0,1,2,...,N].
A case that works:
A case that does not works:
My code:
import matplotlib.pyplot as chart
from matplotlib import lines
# Settings
chart.title(file_name)
chart.xlabel('Years')
chart.ylabel('Committers/Contributions')
chart.ylim([0,highest_value + 100])
chart.xlim(first_year,2017)
# Values
committer_line = chart.plot(committers_dict.keys(),committers_dict.values(),'r',label='Committer')
contribution_line = chart.plot(contributions_dict.keys(),contributions_dict.values(),'b--',label='Contribution')
years = list(range(first_year,2017))
chart.xticks(years)
# Legend
chart.legend()
# Show/Save
chart.savefig(images_path + file_name.replace('.txt','-commiter-contribution.eps'), format='eps')
chart.show()
python matplotlib
python matplotlib
edited Nov 11 at 7:03
Cœur
17k9102140
17k9102140
asked Mar 23 '16 at 17:32
Felipe Fronchetti
225
225
Note that it is not reverting to [0,1,2...N] as in the bottom right you can see +2.011e3 meaning it is actually plotting 2011,2012 and so on, so it is just a matter of how you are showing it.
– Alessandro
Mar 23 '16 at 18:07
add a comment |
Note that it is not reverting to [0,1,2...N] as in the bottom right you can see +2.011e3 meaning it is actually plotting 2011,2012 and so on, so it is just a matter of how you are showing it.
– Alessandro
Mar 23 '16 at 18:07
Note that it is not reverting to [0,1,2...N] as in the bottom right you can see +2.011e3 meaning it is actually plotting 2011,2012 and so on, so it is just a matter of how you are showing it.
– Alessandro
Mar 23 '16 at 18:07
Note that it is not reverting to [0,1,2...N] as in the bottom right you can see +2.011e3 meaning it is actually plotting 2011,2012 and so on, so it is just a matter of how you are showing it.
– Alessandro
Mar 23 '16 at 18:07
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Matplotlib is putting the correct numbers but in scientific notation because there's no more room in the x-axis to put more stuff. That said you can interact directly with the x-axis and state what strings do you want, in what positions, using a value for rotation. The following example (data was randomized):
import matplotlib.pyplot as chart
from matplotlib import lines
import random
title = 'Title'
first_year = 1960
last_year = 2017
x = [year for year in range(first_year,2017)]
y1 = [random.randint(0,10) for year in range(first_year,2017)]
y2 = [random.randint(0,10) for year in range(first_year,2017)]
highest_value = max(y1+y2)
# Settings
chart.title(title)
chart.xlabel('Years')
chart.ylabel('Committers/Contributions')
chart.ylim([0,highest_value + 0.05*highest_value])
chart.xlim(first_year,last_year)
# Values
committer_line = chart.plot(x,y1,'r',label='Committer')
contribution_line = chart.plot(x,y2,'b--',label='Contribution')
years = list(range(first_year,last_year))
years_str = [str(i) for i in range(first_year,last_year)]
chart.xticks(years,years_str,rotation=45)
# Legend
chart.legend()
# Show/Save
#chart.savefig(images_path + file_name.replace('.txt','-commiter-contribution.eps'), format='eps')
chart.show()
, results in:
, which is a bit cluttered so giving a step to you "Label Code" range:
years = list(range(first_year,last_year,5)) # It's 5!
years_str = [str(i) for i in range(first_year,last_year,5)] # It's 5!
, will ease the x axis information:
add a comment |
up vote
1
down vote
If you look in the lower right hand corner, you'll see that matplotlib simply changed the display of the xtick labels to use scientific notation to save space. To change this you will want to alter the tick label Formatter
.
To disable this conversion to scientific notation, you can tweak the default formatter:
ax.get_xaxis().get_major_formatter().set_useOffset(False)
This edits the useOffset
parameter of your ScalarFormatter
.
If you want to disable this behavior by default, you can edit the axes.formatter.useoffset
rcparam.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Matplotlib is putting the correct numbers but in scientific notation because there's no more room in the x-axis to put more stuff. That said you can interact directly with the x-axis and state what strings do you want, in what positions, using a value for rotation. The following example (data was randomized):
import matplotlib.pyplot as chart
from matplotlib import lines
import random
title = 'Title'
first_year = 1960
last_year = 2017
x = [year for year in range(first_year,2017)]
y1 = [random.randint(0,10) for year in range(first_year,2017)]
y2 = [random.randint(0,10) for year in range(first_year,2017)]
highest_value = max(y1+y2)
# Settings
chart.title(title)
chart.xlabel('Years')
chart.ylabel('Committers/Contributions')
chart.ylim([0,highest_value + 0.05*highest_value])
chart.xlim(first_year,last_year)
# Values
committer_line = chart.plot(x,y1,'r',label='Committer')
contribution_line = chart.plot(x,y2,'b--',label='Contribution')
years = list(range(first_year,last_year))
years_str = [str(i) for i in range(first_year,last_year)]
chart.xticks(years,years_str,rotation=45)
# Legend
chart.legend()
# Show/Save
#chart.savefig(images_path + file_name.replace('.txt','-commiter-contribution.eps'), format='eps')
chart.show()
, results in:
, which is a bit cluttered so giving a step to you "Label Code" range:
years = list(range(first_year,last_year,5)) # It's 5!
years_str = [str(i) for i in range(first_year,last_year,5)] # It's 5!
, will ease the x axis information:
add a comment |
up vote
1
down vote
accepted
Matplotlib is putting the correct numbers but in scientific notation because there's no more room in the x-axis to put more stuff. That said you can interact directly with the x-axis and state what strings do you want, in what positions, using a value for rotation. The following example (data was randomized):
import matplotlib.pyplot as chart
from matplotlib import lines
import random
title = 'Title'
first_year = 1960
last_year = 2017
x = [year for year in range(first_year,2017)]
y1 = [random.randint(0,10) for year in range(first_year,2017)]
y2 = [random.randint(0,10) for year in range(first_year,2017)]
highest_value = max(y1+y2)
# Settings
chart.title(title)
chart.xlabel('Years')
chart.ylabel('Committers/Contributions')
chart.ylim([0,highest_value + 0.05*highest_value])
chart.xlim(first_year,last_year)
# Values
committer_line = chart.plot(x,y1,'r',label='Committer')
contribution_line = chart.plot(x,y2,'b--',label='Contribution')
years = list(range(first_year,last_year))
years_str = [str(i) for i in range(first_year,last_year)]
chart.xticks(years,years_str,rotation=45)
# Legend
chart.legend()
# Show/Save
#chart.savefig(images_path + file_name.replace('.txt','-commiter-contribution.eps'), format='eps')
chart.show()
, results in:
, which is a bit cluttered so giving a step to you "Label Code" range:
years = list(range(first_year,last_year,5)) # It's 5!
years_str = [str(i) for i in range(first_year,last_year,5)] # It's 5!
, will ease the x axis information:
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Matplotlib is putting the correct numbers but in scientific notation because there's no more room in the x-axis to put more stuff. That said you can interact directly with the x-axis and state what strings do you want, in what positions, using a value for rotation. The following example (data was randomized):
import matplotlib.pyplot as chart
from matplotlib import lines
import random
title = 'Title'
first_year = 1960
last_year = 2017
x = [year for year in range(first_year,2017)]
y1 = [random.randint(0,10) for year in range(first_year,2017)]
y2 = [random.randint(0,10) for year in range(first_year,2017)]
highest_value = max(y1+y2)
# Settings
chart.title(title)
chart.xlabel('Years')
chart.ylabel('Committers/Contributions')
chart.ylim([0,highest_value + 0.05*highest_value])
chart.xlim(first_year,last_year)
# Values
committer_line = chart.plot(x,y1,'r',label='Committer')
contribution_line = chart.plot(x,y2,'b--',label='Contribution')
years = list(range(first_year,last_year))
years_str = [str(i) for i in range(first_year,last_year)]
chart.xticks(years,years_str,rotation=45)
# Legend
chart.legend()
# Show/Save
#chart.savefig(images_path + file_name.replace('.txt','-commiter-contribution.eps'), format='eps')
chart.show()
, results in:
, which is a bit cluttered so giving a step to you "Label Code" range:
years = list(range(first_year,last_year,5)) # It's 5!
years_str = [str(i) for i in range(first_year,last_year,5)] # It's 5!
, will ease the x axis information:
Matplotlib is putting the correct numbers but in scientific notation because there's no more room in the x-axis to put more stuff. That said you can interact directly with the x-axis and state what strings do you want, in what positions, using a value for rotation. The following example (data was randomized):
import matplotlib.pyplot as chart
from matplotlib import lines
import random
title = 'Title'
first_year = 1960
last_year = 2017
x = [year for year in range(first_year,2017)]
y1 = [random.randint(0,10) for year in range(first_year,2017)]
y2 = [random.randint(0,10) for year in range(first_year,2017)]
highest_value = max(y1+y2)
# Settings
chart.title(title)
chart.xlabel('Years')
chart.ylabel('Committers/Contributions')
chart.ylim([0,highest_value + 0.05*highest_value])
chart.xlim(first_year,last_year)
# Values
committer_line = chart.plot(x,y1,'r',label='Committer')
contribution_line = chart.plot(x,y2,'b--',label='Contribution')
years = list(range(first_year,last_year))
years_str = [str(i) for i in range(first_year,last_year)]
chart.xticks(years,years_str,rotation=45)
# Legend
chart.legend()
# Show/Save
#chart.savefig(images_path + file_name.replace('.txt','-commiter-contribution.eps'), format='eps')
chart.show()
, results in:
, which is a bit cluttered so giving a step to you "Label Code" range:
years = list(range(first_year,last_year,5)) # It's 5!
years_str = [str(i) for i in range(first_year,last_year,5)] # It's 5!
, will ease the x axis information:
answered Mar 23 '16 at 18:07
armatita
5,76042437
5,76042437
add a comment |
add a comment |
up vote
1
down vote
If you look in the lower right hand corner, you'll see that matplotlib simply changed the display of the xtick labels to use scientific notation to save space. To change this you will want to alter the tick label Formatter
.
To disable this conversion to scientific notation, you can tweak the default formatter:
ax.get_xaxis().get_major_formatter().set_useOffset(False)
This edits the useOffset
parameter of your ScalarFormatter
.
If you want to disable this behavior by default, you can edit the axes.formatter.useoffset
rcparam.
add a comment |
up vote
1
down vote
If you look in the lower right hand corner, you'll see that matplotlib simply changed the display of the xtick labels to use scientific notation to save space. To change this you will want to alter the tick label Formatter
.
To disable this conversion to scientific notation, you can tweak the default formatter:
ax.get_xaxis().get_major_formatter().set_useOffset(False)
This edits the useOffset
parameter of your ScalarFormatter
.
If you want to disable this behavior by default, you can edit the axes.formatter.useoffset
rcparam.
add a comment |
up vote
1
down vote
up vote
1
down vote
If you look in the lower right hand corner, you'll see that matplotlib simply changed the display of the xtick labels to use scientific notation to save space. To change this you will want to alter the tick label Formatter
.
To disable this conversion to scientific notation, you can tweak the default formatter:
ax.get_xaxis().get_major_formatter().set_useOffset(False)
This edits the useOffset
parameter of your ScalarFormatter
.
If you want to disable this behavior by default, you can edit the axes.formatter.useoffset
rcparam.
If you look in the lower right hand corner, you'll see that matplotlib simply changed the display of the xtick labels to use scientific notation to save space. To change this you will want to alter the tick label Formatter
.
To disable this conversion to scientific notation, you can tweak the default formatter:
ax.get_xaxis().get_major_formatter().set_useOffset(False)
This edits the useOffset
parameter of your ScalarFormatter
.
If you want to disable this behavior by default, you can edit the axes.formatter.useoffset
rcparam.
edited Mar 23 '16 at 18:12
answered Mar 23 '16 at 18:07
Suever
53k134965
53k134965
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36184953%2fspecifying-values-for-my-x-axis-using-the-matplotlib-pyplot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Note that it is not reverting to [0,1,2...N] as in the bottom right you can see +2.011e3 meaning it is actually plotting 2011,2012 and so on, so it is just a matter of how you are showing it.
– Alessandro
Mar 23 '16 at 18:07