Evenly spaced x-ticks labels
up vote
0
down vote
favorite
I have a dataframe that I have plotted. I want to label the x-axis using a df_dt dataframe column shown below
Date
2007_8
2008_8
2009_8
2010_8
2011_8
2012_8
2013_8
I have the following plot code
plt.style.use('seaborn-colorblind')
ax=df_final.T.plot()
ax.set_xticks(np.arange(len(df_dt)))
ax.set_xticklabels(df_dt['Date'])
However the x-ticks are compressed to one end of the plot to be meaningful. I searched through some threads and most of them suggest adding ax.set_xticks. However that doesnt seem to work for me as seen below. How do i fix the spacing in my x-axis?

python matplotlib
add a comment |
up vote
0
down vote
favorite
I have a dataframe that I have plotted. I want to label the x-axis using a df_dt dataframe column shown below
Date
2007_8
2008_8
2009_8
2010_8
2011_8
2012_8
2013_8
I have the following plot code
plt.style.use('seaborn-colorblind')
ax=df_final.T.plot()
ax.set_xticks(np.arange(len(df_dt)))
ax.set_xticklabels(df_dt['Date'])
However the x-ticks are compressed to one end of the plot to be meaningful. I searched through some threads and most of them suggest adding ax.set_xticks. However that doesnt seem to work for me as seen below. How do i fix the spacing in my x-axis?

python matplotlib
Apparently,df_dtis much shorter thandf_final, so only the firstlen(df_dt)points are labeled.
– ImportanceOfBeingErnest
Nov 8 at 19:59
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a dataframe that I have plotted. I want to label the x-axis using a df_dt dataframe column shown below
Date
2007_8
2008_8
2009_8
2010_8
2011_8
2012_8
2013_8
I have the following plot code
plt.style.use('seaborn-colorblind')
ax=df_final.T.plot()
ax.set_xticks(np.arange(len(df_dt)))
ax.set_xticklabels(df_dt['Date'])
However the x-ticks are compressed to one end of the plot to be meaningful. I searched through some threads and most of them suggest adding ax.set_xticks. However that doesnt seem to work for me as seen below. How do i fix the spacing in my x-axis?

python matplotlib
I have a dataframe that I have plotted. I want to label the x-axis using a df_dt dataframe column shown below
Date
2007_8
2008_8
2009_8
2010_8
2011_8
2012_8
2013_8
I have the following plot code
plt.style.use('seaborn-colorblind')
ax=df_final.T.plot()
ax.set_xticks(np.arange(len(df_dt)))
ax.set_xticklabels(df_dt['Date'])
However the x-ticks are compressed to one end of the plot to be meaningful. I searched through some threads and most of them suggest adding ax.set_xticks. However that doesnt seem to work for me as seen below. How do i fix the spacing in my x-axis?

python matplotlib
python matplotlib
edited Nov 8 at 18:26
SPYBUG96
4291522
4291522
asked Nov 8 at 18:01
sudhasethu
12
12
Apparently,df_dtis much shorter thandf_final, so only the firstlen(df_dt)points are labeled.
– ImportanceOfBeingErnest
Nov 8 at 19:59
add a comment |
Apparently,df_dtis much shorter thandf_final, so only the firstlen(df_dt)points are labeled.
– ImportanceOfBeingErnest
Nov 8 at 19:59
Apparently,
df_dt is much shorter than df_final, so only the first len(df_dt) points are labeled.– ImportanceOfBeingErnest
Nov 8 at 19:59
Apparently,
df_dt is much shorter than df_final, so only the first len(df_dt) points are labeled.– ImportanceOfBeingErnest
Nov 8 at 19:59
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53213618%2fevenly-spaced-x-ticks-labels%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
Apparently,
df_dtis much shorter thandf_final, so only the firstlen(df_dt)points are labeled.– ImportanceOfBeingErnest
Nov 8 at 19:59