2016-07-01 10 views
2

私はIPythonノートブックでplotly(オフラインバージョン)を使用しています。私はそれが大好きです。しかし、私は垂直線または垂直線をプロットする方法を見つけることができませんでした。 matplotlibの中無限の線とスパンを描画する方法をPythonでプロットするか?

同等物は、以下のとおりです。

import matplotlib.plyplot as plt 
plt.axvline(x=0) 
plt.axvspan(xmin=0, xmax=1) 

おかげで、事前

答えて

0

に私はちょうどplotly自分で出始めている、とこれまでのところ、私はこれを行うには良い方法を発見していません。しかし、1つの水平または垂直線だけが必要な場合、以下のコードは実行可能なハックと思われます。デフォルトのグリッドを使用することですが、目的の高さに1つのグリッド線を描画します。あなたのレイアウトdictに次のものを含めてください。ylineに水平線をプロットします。

yaxis=dict(
     zeroline=False, 
     autotick=False, 
     showgrid=True, 
     tick0=yline, 
     dtick=<something very large, so that next lines are out of range> 
) 
0

私はレイアウトで「シェイプ」オプションを使用します。例えば、X = 6で縦線を取得する:

layout = {'title' : 'example', 
      'shapes' : [{'type' : 'line', 'x0' : 6, 
         'x1' : 6, 'y0' : 0, 'y1' : 10, 
         'width' : 1}]} 

をあなたは垂直方向のバンドをプロットする幅のパラメータを変更することができます。

1

プロットレイアウトにシェイプを追加できます。図形には線や矩形を含めることができます。また、特定の軸ではなく、プロット領域を基準に描画することで無制限にすることもできます。 plotly shapes docsの例を見てください。

layout = { 
     'title': "My Chart", 
     'shapes': [ 
      { # Unbounded line at x = 4 
       'type': 'line', 
       # x-reference is assigned to the x-values 
       'xref': 'x', 
       # y-reference is assigned to the plot paper [0,1] 
       'yref': 'paper', 
       'x0': 4, 
       'y0': 0, 
       'x1': 4, 
       'y1': 1, 
       'line': { 
        'color': 'rgb(55, 128, 191)', 
        'width': 3, 
       } 
      }, 
      { # Unbounded span at 6 <= x <= 8 
       'type': 'rect', 
       # x-reference is assigned to the x-values 
       'xref': 'x', 
       # y-reference is assigned to the plot paper [0,1] 
       'yref': 'paper', 
       'x0': 6, 
       'y0': 0, 
       'x1': 8, 
       'y1': 1, 
       'fillcolor': '#d3d3d3', 
       'opacity': 0.2, 
       'line': { 
        'width': 0, 
       } 
      } 
     ], 
    } 
関連する問題