亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

因子圖的軸有什么問題?

因子圖的軸有什么問題?

阿晨1998 2022-09-20 17:23:07
我有這個數據集:kaggle:房價:高級回歸技術。我按如下方式加載了它:import numpy as npimport pandas as pdimport matplotlib.pyplot as plt%matplotlib inlineimport seaborn as snsimport scipy.stats as sttrain = pd.read_csv("train.csv")然后,我嘗試使用整體質量作為色調,按年份構建繪制銷售價格:plt.figure(figsize = [8, 6])sns.factorplot(    x = 'YearBuilt',    y = 'SalePrice',     data = train,    kind='swarm',    hue='OverallQual',    palette = 'Set2')plt.title('House Sale Prices (log scale) vs. Year Built and Overall Quality')plt.xticks([1880, 1900, 1920, 1940, 1960, 1980, 2000], ['1880', '1900', '1920', '1940', '1960', '1980', '2000'])#plt.xlim([1872,2009])plt.xlabel('Year Built')plt.yscale('log')#plt.ylim([4e4, 6e5])plt.yticks([6e4, 1e5, 1.4e5, 1.8e5, 2.4e5, 3.2e5, 4e5, 6e5], ['60k', '100k', '140K', '180k', '240K', '320k', '600k'])plt.ylabel('Sale Price ($)')plt.show()結果如下圖所示:如果我包含 xlim 或 ylim,則圖形根本不會顯示出來。我是新手,所以任何幫助都非常感謝。
查看完整描述

1 回答

?
蕪湖不蕪

TA貢獻1796條經驗 獲得超7個贊

plt.style.use('ggplot')

g = sns.catplot(

    x = 'YearBuilt',

    y = 'SalePrice',

    data = train,

    kind='swarm',

    hue='OverallQual',

    palette = 'Set2', height=6, aspect=2)


locs, labels = plt.xticks()  # use if needed, as explained below.


for axes in g.axes.flat:


    for ind, label in enumerate(axes.get_xticklabels()):

        if ind % 8 == 0:  # every nth label is kept

            label.set_visible(True)

        else:

            label.set_visible(False)



plt.title('House Sale Prices (log scale) vs. Year Built and Overall Quality')

plt.xlabel('Year Built')

plt.yscale('log')

plt.ylim([4e4, 6e5])

plt.yticks([6e4, 1e5, 1.4e5, 1.8e5, 2.4e5, 3.2e5, 4e5, 6e5], ['60k', '100k', '140K', '180k', '240K', '320k', '600k'])

plt.ylabel('Sale Price ($)')

plt.show()

http://img1.sycdn.imooc.com//632986da000145b309240428.jpg

plt.style.use('ggplot')

g = sns.catplot(

    x = 'YearBuilt',

    y = 'SalePrice',

    data = train,

    kind='swarm',

    hue='OverallQual',

    palette = 'Set2', height=6, aspect=2)


locs, labels = plt.xticks()  # use if needed, as explained below.


for axes in g.axes.flat:


    for ind, label in enumerate(axes.get_xticklabels()):

        if ind % 8 == 0:  # every nth label is kept

            label.set_visible(True)

        else:

            label.set_visible(False)



plt.title('House Sale Prices (log scale) vs. Year Built and Overall Quality')

plt.xlabel('Year Built')

plt.yscale('log')

plt.ylim([4e4, 6e5])

plt.yticks([6e4, 1e5, 1.4e5, 1.8e5, 2.4e5, 3.2e5, 4e5, 6e5], ['60k', '100k', '140K', '180k', '240K', '320k', '600k'])

plt.ylabel('Sale Price ($)')

plt.show()

http://img1.sycdn.imooc.com//632986fd000180a009290434.jpg

查看完整回答
反對 回復 2022-09-20
  • 1 回答
  • 0 關注
  • 72 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號