科学の箱

科学・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

errorbarで誤差棒付きグラフの作成

概要 学習モデルのグラフは誤差を含んでいる。今2軸(xおよびy)をとり、以下のようなモデルに近似したとする。実際のデータは誤差がある。この誤差を表示できるのがerrorbarである。 ドキュメント h …

no image

特定のパッケージのためのgitignoreを作成したい

https://gitignore.ioを開く パッケージ名を入力 Createをクリック Related posts:dataframeで条件を付けて要素を返す方法SIGNATE お弁当の需要予測- …

no image

pythonで地理情報を取り扱う

pythonでデータ分析をして地理情報に表示したいときに使うパッケージはplotlyである。 plotlyのchropleth map(階級区分図)を利用する。 plotlyについてはこちらでサンプル …

no image

グラフの軸を操作する

概要 ここでは以下の項目について取り扱う 軸にラベルを設定する ー xlabel, ylabel 軸の最小値、最大値を設定する ー xlim, ylim, xaxis 軸にメモリを設定する ー xti …

no image

データ分析で理解しておくべきPythonのデータ構造

Pythonでデータ分析を行う際には基本のデータ構造を理解しておく必要がある。 scikit-learnなどのフレームワークは特定のデータ構造を入力とすることを前提にしている。用意したデータがフレーム …

2019年10月
月 火 水 木 金 土 日
« 9月   11月 »
 123456
78910111213
14151617181920
21222324252627
28293031  

side bar top



アーカイブ

カテゴリー