第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何旋轉(zhuǎn)seaborn barplot x軸刻度標(biāo)簽

如何旋轉(zhuǎn)seaborn barplot x軸刻度標(biāo)簽

Helenr 2022-10-18 17:27:29
我試圖讓一個(gè)條形圖將它的 X 標(biāo)簽旋轉(zhuǎn) 45°,以使它們可讀(因?yàn)榇嬖谥丿B)。len(genero)7歲,len(filmes_por_genero)20歲我正在使用 MovieLens 數(shù)據(jù)集并制作一個(gè)圖表,計(jì)算每種類(lèi)型的電影數(shù)量。這是我現(xiàn)在的代碼:import seaborn as snsimport matplotlib.pyplot as pltsns.set_style("whitegrid")filmes_por_genero = filmes["generos"].str.get_dummies('|').sum().sort_values(ascending=False)genero = filmes_com_media.indexchart = plt.figure(figsize=(16,8))sns.barplot(x=genero,            y=filmes_por_genero.values,            palette=sns.color_palette("BuGn_r", n_colors=len(filmes_por_genero) + 4)            )chart.set_xticklabels(    chart.get_xticklabels(),     rotation=45,     horizontalalignment='right')這是完整的錯(cuò)誤:/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/grouper.py in get_grouper(obj, key, axis, level, sort, observed, mutated, validate)    623                 in_axis=in_axis,    624             )--> 625             if not isinstance(gpr, Grouping)    626             else gpr    627         )/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/grouper.py in __init__(self, index, grouper, obj, name, level, sort, observed, in_axis)    254         self.name = name    255         self.level = level--> 256         self.grouper = _convert_grouper(index, grouper)    257         self.all_grouper = None    258         self.index = index/usr/local/lib/python3.6/dist-packages/pandas/core/groupby/grouper.py in _convert_grouper(axis, grouper)    653     elif isinstance(grouper, (list, Series, Index, np.ndarray)):    654         if len(grouper) != len(axis):--> 655             raise ValueError("Grouper and axis must be same length")    656         return grouper    657     else:ValueError: Grouper and axis must be same length
查看完整描述

1 回答

?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊

import pandas as pd

import matplotlib.pyplot as plt

import seaborn as sns

sns.set_style("whitegrid")


# data

df = pd.read_csv('ml-25m/movies.csv')


print(df.head())


   movieId                               title                                       genres

0        1                    Toy Story (1995)  Adventure|Animation|Children|Comedy|Fantasy

1        2                      Jumanji (1995)                   Adventure|Children|Fantasy

2        3             Grumpier Old Men (1995)                               Comedy|Romance

3        4            Waiting to Exhale (1995)                         Comedy|Drama|Romance

4        5  Father of the Bride Part II (1995)                                       Comedy


# clean genres

df['genres'] = df['genres'].str.split('|')

df = df.explode('genres').reset_index(drop=True)


print(df.head())


   movieId             title     genres

0        1  Toy Story (1995)  Adventure

1        1  Toy Story (1995)  Animation

2        1  Toy Story (1995)   Children

3        1  Toy Story (1995)     Comedy

4        1  Toy Story (1995)    Fantasy


流派很重要

gc = df.genres.value_counts().to_frame()


print(genre_count)


                    genres

Drama                25606

Comedy               16870

Thriller              8654

Romance               7719

Action                7348

Horror                5989

Documentary           5605

Crime                 5319

(no genres listed)    5062

Adventure             4145

Sci-Fi                3595

Children              2935

Animation             2929

Mystery               2925

Fantasy               2731

War                   1874

Western               1399

Musical               1054

Film-Noir              353

IMAX                   195

陰謀:sns.barplot

ax

fig, ax = plt.subplots(figsize=(12, 6))

sns.barplot(x=gc.index, y=gc.genres, palette=sns.color_palette("BuGn_r", n_colors=len(genre_count) + 4), ax=ax)

ax.set_xticklabels(ax.get_xticklabels(), rotation=45, horizontalalignment='right')

plt.show()

沒(méi)有ax


plt.figure(figsize=(12, 6))

chart = sns.barplot(x=gc.index, y=gc.genres, palette=sns.color_palette("BuGn_r", n_colors=len(genre_count)))

chart.set_xticklabels(chart.get_xticklabels(), rotation=45, horizontalalignment='right')

plt.show()

http://img1.sycdn.imooc.com//634e71b800015a8107350421.jpg

陰謀:sns.countplot

  • 如果情節(jié)順序無(wú)關(guān)緊要,請(qǐng)使用sns.countplot跳過(guò)使用。.value_counts()

  • 要訂購(gòu)countplot,order=df.genres.value_counts().index必須使用,所以如果需要降序,countplot并不能真正使您免于需要 。.value_counts()

fig, ax = plt.subplots(figsize=(12, 6))

sns.countplot(data=df, x='genres', ax=ax)

ax.set_xticklabels(ax.get_xticklabels(), rotation=45, horizontalalignment='right')

plt.show()

http://img1.sycdn.imooc.com//634e71ca0001dd3907460439.jpg

查看完整回答
反對(duì) 回復(fù) 2022-10-18
  • 1 回答
  • 0 關(guān)注
  • 471 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)