matplotlib python3

matplotlib で csv ファイルからデータを読み込んでグラフを表示する方法

投稿日:

np loadtext で csv ファイルを読み込む。

pyplot.bar で棒グラフを表示する。

import numpy as np
from matplotlib import pyplot as plt

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

for data in data_set:
    plt.bar(data[0],data[1])

plt.show()

data.csv

25,39
26,41
27,50

結果

-matplotlib, python3
-,

執筆者:


comment

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

関連記事

no image

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

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

no image

python3 でリストを結合する方法

2つのリストを結合して、「リストのリストを作りたい場合」と、「1つの長いリストを作りたい」場合がある。 それぞれ、次のようにする。 例 # リスト2つを用意 l_1 = [1,2,3] l_2 …

no image

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

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

no image

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

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

no image

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

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