0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

matplitlibでグラフが真っ白になって何も表示されないときの対処法

Last updated at Posted at 2025-01-09

課題

plt.bar()で領域は正しく表示されているのに、中身が表示されなくて困った。

import matplotlib.pyplot as plt

A = [10000, 11000, 12000]
B = [2.0, 3.0, 1.0]
plt.bar(A, B)
plt.show()

Gg3Zw7GbcAAfqbD.png

原因

X軸のスケールに対してバーの横幅(width)が小さすぎることが原因。

公式ドキュメント

width : float or array-like, default: 0.8

と書いてある通り、バーの横幅は(指定しない限り)0.8固定であり、勝手にスケーリングしてくれるわけではない。

解決策

適当に横幅を指定してやればよい

import matplotlib.pyplot as plt

A = [10000, 11000, 12000]
B = [2.0, 3.0, 1.0]
plt.bar(A, B,width=300)
plt.show()

スクリーンショット 2025-01-10 015341.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?