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

python の for ループで、データだけでなくインデックスも一緒に取得する

通常の for ループではなく、enumerate() を使うとインデックスが取得できる。 例 list1 = [’太郎’,’次郎’,’三郎’] for i, name in enumerat …

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

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

no image

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

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

no image

python3 で文字列を入力させて受け取る方法

C言語で scanf のようなものを作るには、python では input() で実現できる。 例 print(‘xの値を入力してください’) x = input() print(‘xの値は ‘ + …

no image

python3 で、すべて小文字かどうかを判定する方法

islower() 関数を使う。 例 print(‘abcde’.islower()) print(‘abcDe’.islower()) 結果 True False