matplotlib python3

matplotlib でcsv ファイルを読み込むとき、最初の行をスキップする方法

投稿日:

numpy の loadtxt で読み込む行を省略したい場合

スキップしたい行を # 等の記号でコメントアウトして、

loadtxt の comments = ‘#’ とすると省略できる。

import numpy as np
from matplotlib import pyplot as plt

data_set = np.loadtxt(fname='data.csv',dtype='float',delimiter=',',  comments='#')

fig, ax = plt.subplots()

size = 300
for data in data_set:
    ax.scatter(data[0],data[1],size,'blue')

plt.show()

data.csv

# first second
1,3
2,7
3,9
# 4,7
5,1

結果

-matplotlib, python3
-,

執筆者:


comment

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

関連記事

no image

matplotlib で、グラフ内に注釈ラベルをつける方法

annotate を使う 例 import numpy as np import matplotlib.pyplot as plt ax = plt.figure().add_subplot() th …

no image

matplotlib で、2種類のデータをプロットする方法

下では、凡例(legend)を設定している。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = [ …

no image

matplotlib で、凡例を表示する位置を変更する方法

凡例(legend)の表示位置を変更するには、axis の legend の loc を設定する。 次のリンクhttps://matplotlib.org/stable/api/_as_gen/mat …

no image

python3 で csv ファイルを読み込んで、最初の数行を表示する方法

以下の例では、空の配列 data を用意しておき、最初の3行を読み込んでおく。 例 import csv with open(‘data.csv’,’r’) as csv_file: csv_read …

no image

python3 で、dictionary のキー一覧を取得する方法

dict.keys() でキーを取得することができる。 参考:dictionary の値一覧を取得するときは、dict.values() を使う。 例 print(dict.keys())