Same axis order in two graphs












1















I have this function:



def plot_stats_test(feature,label_rotation=False,horizontal_layout=True):

temp = df_test_2[feature].value_counts()
df1 = pd.DataFrame({feature: temp.index,'Количество клиентов': temp.values})

# Расчет доли target=1 в категории
cat_perc = df_train_2[[feature, Target']].groupby([feature],as_index=False).mean()

if(horizontal_layout):
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,6))
else:
fig, (ax1, ax2) = plt.subplots(nrows=2, figsize=(12,14))
sns.set_color_codes("pastel")

s = sns.barplot(ax=ax1, x = feature, y="Количество клиентов",data=df1)
if(label_rotation):
s.set_xticklabels(s.get_xticklabels(),rotation=90)
plt.tick_params(axis='both', which='major', labelsize=12)

s = sns.barplot(ax=ax2, x = feature, y='Target', data=cat_perc, order=cat_perc[feature])

if(label_rotation):
s.set_xticklabels(s.get_xticklabels(),rotation=90)
plt.ylabel('Доля продленных', fontsize=10)
plt.tick_params(axis='both', which='major', labelsize=10)

plt.show();


![enter image description here][1]




  1. How to make the X axis signature on the right graph in the same order as the left graph?










share|improve this question

























  • Please provide a Minimal, Complete, and Verifiable example - this includes a sample input and how you call your function. Please only ask one question - 2. is different from your original problem and should be asked in a separate question.

    – Mr. T
    Nov 26 '18 at 7:30











  • adding sorted to s.get_xticklabels()

    – Sembei Norimaki
    Nov 26 '18 at 14:08
















1















I have this function:



def plot_stats_test(feature,label_rotation=False,horizontal_layout=True):

temp = df_test_2[feature].value_counts()
df1 = pd.DataFrame({feature: temp.index,'Количество клиентов': temp.values})

# Расчет доли target=1 в категории
cat_perc = df_train_2[[feature, Target']].groupby([feature],as_index=False).mean()

if(horizontal_layout):
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,6))
else:
fig, (ax1, ax2) = plt.subplots(nrows=2, figsize=(12,14))
sns.set_color_codes("pastel")

s = sns.barplot(ax=ax1, x = feature, y="Количество клиентов",data=df1)
if(label_rotation):
s.set_xticklabels(s.get_xticklabels(),rotation=90)
plt.tick_params(axis='both', which='major', labelsize=12)

s = sns.barplot(ax=ax2, x = feature, y='Target', data=cat_perc, order=cat_perc[feature])

if(label_rotation):
s.set_xticklabels(s.get_xticklabels(),rotation=90)
plt.ylabel('Доля продленных', fontsize=10)
plt.tick_params(axis='both', which='major', labelsize=10)

plt.show();


![enter image description here][1]




  1. How to make the X axis signature on the right graph in the same order as the left graph?










share|improve this question

























  • Please provide a Minimal, Complete, and Verifiable example - this includes a sample input and how you call your function. Please only ask one question - 2. is different from your original problem and should be asked in a separate question.

    – Mr. T
    Nov 26 '18 at 7:30











  • adding sorted to s.get_xticklabels()

    – Sembei Norimaki
    Nov 26 '18 at 14:08














1












1








1








I have this function:



def plot_stats_test(feature,label_rotation=False,horizontal_layout=True):

temp = df_test_2[feature].value_counts()
df1 = pd.DataFrame({feature: temp.index,'Количество клиентов': temp.values})

# Расчет доли target=1 в категории
cat_perc = df_train_2[[feature, Target']].groupby([feature],as_index=False).mean()

if(horizontal_layout):
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,6))
else:
fig, (ax1, ax2) = plt.subplots(nrows=2, figsize=(12,14))
sns.set_color_codes("pastel")

s = sns.barplot(ax=ax1, x = feature, y="Количество клиентов",data=df1)
if(label_rotation):
s.set_xticklabels(s.get_xticklabels(),rotation=90)
plt.tick_params(axis='both', which='major', labelsize=12)

s = sns.barplot(ax=ax2, x = feature, y='Target', data=cat_perc, order=cat_perc[feature])

if(label_rotation):
s.set_xticklabels(s.get_xticklabels(),rotation=90)
plt.ylabel('Доля продленных', fontsize=10)
plt.tick_params(axis='both', which='major', labelsize=10)

plt.show();


![enter image description here][1]




  1. How to make the X axis signature on the right graph in the same order as the left graph?










share|improve this question
















I have this function:



def plot_stats_test(feature,label_rotation=False,horizontal_layout=True):

temp = df_test_2[feature].value_counts()
df1 = pd.DataFrame({feature: temp.index,'Количество клиентов': temp.values})

# Расчет доли target=1 в категории
cat_perc = df_train_2[[feature, Target']].groupby([feature],as_index=False).mean()

if(horizontal_layout):
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12,6))
else:
fig, (ax1, ax2) = plt.subplots(nrows=2, figsize=(12,14))
sns.set_color_codes("pastel")

s = sns.barplot(ax=ax1, x = feature, y="Количество клиентов",data=df1)
if(label_rotation):
s.set_xticklabels(s.get_xticklabels(),rotation=90)
plt.tick_params(axis='both', which='major', labelsize=12)

s = sns.barplot(ax=ax2, x = feature, y='Target', data=cat_perc, order=cat_perc[feature])

if(label_rotation):
s.set_xticklabels(s.get_xticklabels(),rotation=90)
plt.ylabel('Доля продленных', fontsize=10)
plt.tick_params(axis='both', which='major', labelsize=10)

plt.show();


![enter image description here][1]




  1. How to make the X axis signature on the right graph in the same order as the left graph?







python seaborn






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 14:04







lifeisdata

















asked Nov 26 '18 at 7:22









lifeisdatalifeisdata

63




63













  • Please provide a Minimal, Complete, and Verifiable example - this includes a sample input and how you call your function. Please only ask one question - 2. is different from your original problem and should be asked in a separate question.

    – Mr. T
    Nov 26 '18 at 7:30











  • adding sorted to s.get_xticklabels()

    – Sembei Norimaki
    Nov 26 '18 at 14:08



















  • Please provide a Minimal, Complete, and Verifiable example - this includes a sample input and how you call your function. Please only ask one question - 2. is different from your original problem and should be asked in a separate question.

    – Mr. T
    Nov 26 '18 at 7:30











  • adding sorted to s.get_xticklabels()

    – Sembei Norimaki
    Nov 26 '18 at 14:08

















Please provide a Minimal, Complete, and Verifiable example - this includes a sample input and how you call your function. Please only ask one question - 2. is different from your original problem and should be asked in a separate question.

– Mr. T
Nov 26 '18 at 7:30





Please provide a Minimal, Complete, and Verifiable example - this includes a sample input and how you call your function. Please only ask one question - 2. is different from your original problem and should be asked in a separate question.

– Mr. T
Nov 26 '18 at 7:30













adding sorted to s.get_xticklabels()

– Sembei Norimaki
Nov 26 '18 at 14:08





adding sorted to s.get_xticklabels()

– Sembei Norimaki
Nov 26 '18 at 14:08












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476363%2fsame-axis-order-in-two-graphs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476363%2fsame-axis-order-in-two-graphs%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Wiesbaden

To store a contact into the json file from server.js file using a class in NodeJS

Marschland