2017-02-24 5 views
0

"python setup.py install"コマンドを使ってMacに "Gnuplot-py"パッケージをインストールしようとしています。 gnuplotの-PY-1.8ディレクトリ内が、私はこのエラーを取得:Mac OS Sierraで "python setup.py install"コマンドで "Gnuplot-py"をインストールする際のエラーメッセージ

トレースバック(最新の呼び出しの最後):上記の例外の取り扱い中

File "/Users/sebydc77/Downloads/gnuplot-py-1.8/PlotItems.py", line 20, in from cStringIO import StringIO ModuleNotFoundError: No module named 'cStringIO'

を、別の例外が発生しました:

トレースバックを(直近の最後のコール):

File "setup.py", line 15, in from init import version File "/Users/sebydc77/Downloads/gnuplot-py-1.8/init.py", line 166, in from PlotItems import PlotItem, Func, File, Data, GridData File "/Users/sebydc77/Downloads/gnuplot-py-1.8/PlotItems.py", line 22, in from StringIO import StringIO ModuleNotFoundError: No module named 'StringIO'

私はこの問題を解決するために少なくとも3時間を費やしました。前述のように

+0

Python 3(欠落している 'StringIO'モジュールで判断しているようです)のようですか? Gnuplot-pyはPython 2.Xでしか動作しません - http://stackoverflow.com/a/12840346/5351549 – ewcz

+0

あなたは部分的に正しくありました。私は2.7版のミニコンダで新しい環境を作りました。最初はエラーが出ましたが、これらのコマンドはそれを解決しました:1)キャスク/キャスク/アクアテームの醸造2)ビールの再インストールgnuplot - with-aquaterm あなたの助けを大変ありがとうございます! –

答えて

0

:私はまた、等...

(私はすでに自分のマシンにインストールしたgnuplotている注)「...ダウンロードリンクを設置ピップ」とは、「gnuplotの-PYをインストールピップ」など、さまざまな選択肢を試してみましたモジュールはPython 3では動作しません。

カスタムプロット関数を使用すると、Pythonでgnuplotを使用するのは難しくありません。以下は、エポキシ樹脂を用いたカーボンファイバーラミネートの注入のグラフを作成した例です。注入の間、樹脂のペールはスケール上に置かれるので、残りの重量を数分ごとに書き留めることができます。

plotの主な入力は、バケット内の樹脂の時間と量を記録したnumpyアレイです。この量は時間が経つにつれて減少するので、このデータを使用して、注入された樹脂の総量と樹脂が流れる速度を計算します。それはnumpyが便利な場所です!

基本的に、この関数は、gnuplotコマンドとインラインデータを含む行のリストを作成し、それを1つの文字列に結合して、subprocessとして実行するgnuplotに送ります。グラフのスタイルは私のgnuplotrcファイルの設定によって決定されることを example infusion picture

注:

import subprocess 
import numpy as np 


def plot(rawdata, filename, maxy=None, labels=False, n=2): 
    """Plot injection data with gnuplot. 

    Arguments: 
     data: numpy array of shape (N,2) 
      (Time, weight) pairs as written down during the injection. The time 
      in minutes increases and the weight in grams decreases. 
     filename: string 
      Name to write the output figure to. 
     maxy: Maximum y coordinate for the left axis (injected weight). 
      The right axis (injection speed) is 1/10th of the left axis. 
      When set to None, automatic scaling is used. 
     labels: Label every n-th data point when true. 
     n: Print every n-th value as a label. 
    """ 
    gtype = 'lines' 
    if labels: 
     gtype = 'linespoints' 
    delta = rawdata[1:] - rawdata[:-1] 
    totals = np.array([[0, 0]] + [[dt, -dm] for dt, dm in delta]) 
    som = np.cumsum(totals, axis=0) 
    print('harshoeveelheid "{}": {} g'.format(filename, som[-1, 1])) 
    if maxy is None: 
     maxy = round(som[-1, 1], -2) 
    dm = np.array([[0]] + [[-dm/dt] for dt, dm in delta]) 
    newdata = np.hstack((som, dm)) 
    newdata[0, 2] = newdata[1, 2] 
    l1 = 'set label "{:.0f} g" at {},{} center offset 0,0.5' 
    l2 = 'set label "{:.0f} g/min" at {},second {} center offset 0,0.5' 
    p1 = 'plot "-" with {gt} ls 1 title "harshoeveelheid", ' \ 
     '"-" with {gt} axes x1y2 ls 2 title "injectiesnelheid"' 
    lp1 = ', "-" using 1:2:2 with labels right offset character 0.4,0.7' \ 
     'font "Alegreya, 8" tc ls 1 notitle' 
    lp2 = ', "-" using 1:2:2 axis x1y2 with labels left offset character ' \ 
     '0.5,0.7 font "Alegreya, 8" tc ls 2 notitle' 
    text = ['set terminal pdfcairo enhanced color dashed font "Alegreya, 11" ' 
      'rounded size 12.8 cm, 7.0 cm', 
      'set xlabel "tijd [min]"', 
      'set ylabel "harshoeveelheid [g]"', 
      'set y2label "injectiesnelheid [g/min]"', 
      'set y2tics', 
      'set yrange [0:{:.0f}]'.format(maxy), 
      'set y2range [0:{:.0f}]'.format(maxy/10), 
      'set key left bottom', 
      'set grid'] 
    if not labels: 
     text.append(l1.format(newdata[-1, 1], newdata[-1, 0], newdata[-1, 1])) 
     text.append(l2.format(newdata[-1, 2], newdata[-1, 0], newdata[-1, 2])) 
    text.append('set output "{}"'.format(filename + '.pdf')) 
    text.append(p1.format(gt=gtype)) 
    if labels: 
     text[-1] += lp1 + lp2 
    data1 = ['{:2.0f} {:4.0f}'.format(a, b) for a, b, _ in newdata] 
    data2 = ['{:2.0f} {:4.0f}'.format(a, b) for a, _, b in newdata] 
    text += data1 
    text.append('e') 
    text += data2 
    text.append('e') 
    if labels: 
     data1 = ['{:2.0f} {:4.0f}'.format(a, b) for a, b, _ in newdata[n-1::n]] 
     data2 = ['{:2.0f} {:4.0f}'.format(a, b) for a, _, b in newdata[n-1::n]] 
     text += data1 
     text.append('e') 
     text += data2 
     text.append('e') 
    p = subprocess.Popen(['gnuplot'], stdin=subprocess.PIPE) 
    _, _ = p.communicate(input='\n'.join(text).encode('utf-8')) 

出力は次のようになります。

関連する問題