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

python3 でランダムな整数の配列を作る方法

random モジュールを使う。randint() の引数で、配列の最小値と最大値を指定できる。 例 import random random_arr = [random.randint(-2 …

no image

matplotlib でグラフ表示ウィンドウの画面上の位置を自由に設定する方法

matplotlib.use(‘TkAgg’) としておき、 get_current_fig_manager().window.wm_geometry(“+20+50”) として、(+20+50)のと …

no image

python3 で、pathlib を使ってファイルの拡張子を取得する方法

pathlib モジュールの stem を使う。 この書き方は、python 3.4 以降で使えるようになった。 https://docs.python.org/3/library/pathlib.h …

matplotlib のグラフ作成と gnuplot との対応 比較

起動方法 gnuplot コマンドで $ gnuplot とすれば起動できる。 初期設定ファイルは gnuplotrc にある。 gnuplotrc の場所の見つけ方(macの場合) https:// …

no image

python3 で辞書(dictionary)を削除する

clear() することによって、辞書が存在した状態のまま、キーと値をすべて削除することができる。 例 dict1 = {“名前”:”太郎”, “年齢”: 20, “住所”: “東京都千代田区大手町1 …