科学の箱

科学・IT・登山の話題

Python

pyplotでx軸のラベルを90度回転させる

投稿日:

pyplotでx軸にラベルを記載するとラベル文字数が長すぎるためにお互いにオーバーラップしてみにくい。

このよう場合にはpyplot.xticksを実行する際にrotationを指定すればよい。

Rotating custom tick labels — Matplotlib 3.1.1 documentation

rotationはmatplotlib.textで定義されている属性の一部である。ほかにも様々な属性を指定できる。

matplotlib.text

まずrotationを指定しない場合を見てみる。

import matplotlib.pyplot as plt
%matplotlib inline
x = [1, 2, 3, 4]
y = [1, 4, 9, 6]
labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']

plt.plot(x, y)
# You can specify a rotation for the tick labels in degrees or with keywords.
plt.xticks(x, labels)
plt.show()

次にrotationを指定する。

import matplotlib.pyplot as plt
%matplotlib inline
x = [1, 2, 3, 4]
y = [1, 4, 9, 6]
labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']

plt.plot(x, y)
# You can specify a rotation for the tick labels in degrees or with keywords.
plt.xticks(x, labels, rotation='vertical')
plt.show()

メタ情報

inarticle



メタ情報

inarticle



-Python
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

連続データのビジュアル

Kaggle TitanicのFareを使っていくつかビジュアル 金額別ヒストグラム-1 titanic_df[‘Fare’].plot(kind=’hist’, figsize=(15,3),bin …

no image

タプルの操作

タプルはPythonで提供されているデータ構造の一つ。タプルは固定長で変更できない複数の値の集合である。 タプルオブジェクト (tuple object) — Python 3.8.0 ドキュメント …

no image

数字、計算、文字列を画面出力

Hello Worldができたので、いろいろな出力を試してみる。 出力はprint関数を使えばよい。 まずは数値から試してみる。数値は文字列と違い引用符で囲む必要はない。画面に直接表示するので変数は使 …

no image

flickrapiを使うための手順

https://stuvel.eu/flickrapiで提供されるflickrapiを利用するにあたり、エラーが出てインストールできない。 condaでは提供されていない pipはSSLError(S …

no image

requests.exceptions.SSLError: HTTPSConnectionPoolの対応方法

エラー raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host=&#8217 …

2019年10月
« 9月   11月 »
 123456
78910111213
14151617181920
21222324252627
28293031  

side bar top



アーカイブ

カテゴリー