1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pandasでcsv読み込み matplotlibでグラフ

Last updated at Posted at 2020-07-25

メモです。

サンプルコード

pandas_matplotlib.py

import pandas as pd #csv読み込みなどもできる
import matplotlib.pyplot as plt#グラフ描写

file_name = "test.csv"
""" test.csv の中身↓
1, 3, 5
2, 4, 6
"""

#ヘッダーがcsvにないので読み込み時に追加
name_ = ["X", "Y", "Z"]
df = pd.read_csv(file_name, names=name_, encoding='cp932')
print(df)

# fig = plt.figure()
# ax = fig.add_subplot(1,1,1)

#グラフ(X, Y) とグラフ(X, Z)の重ね合わせ
ax = df.plot(x="X",y="Y", color="b", label="Y")
df.plot(x="X",y="Z", color="r", label="Z", ax=ax)
ax.set_xlabel("label_X")
ax.set_ylabel("label_YZ")
plt.show()
fig = ax.get_figure()
fig.subplots_adjust(bottom=0.2)#はみ出し阻止
fig.savefig("pandas_matplotlib.png")

結果

   X  Y  Z
0  1  3  5
1  2  4  6

pandas_matplotlib.png

1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?