2016-11-09 3 views
1

私はPythonのmatplotlibを使用していて、追加の行でmatplotlib.scatter()を作成したいとします。行は、散布図の内容とは関係なく、左下隅から右上隅に進む必要があります。 this postのようなデータの線形回帰は、私が探しているものではありません。また、動的に分散入力とは独立している必要があります。pythonのmatplotlibを使用して散布図に行を追加する

enter image description here

EDIT:

これは、最終的なプロットである必要があり

# Scatter Plot 
x = data_calc_hourly.temp 
y = data_obs_hourly.temp 

lineStart = data_calc_hourly.temp.min() 
lineEnd = data_calc_hourly.temp.max() 

plt.figure() 
plt.scatter(x, y, color = 'k', alpha=0.5) 
plt.plot([lineStart, lineEnd], [lineStart, lineEnd], 'k-', color = 'r') 
plt.xlim(lineStart, lineEnd) 
plt.ylim(lineStart, lineEnd) 
plt.show() 

任意のより良い方法はあり:

これを行うと、私の結果を得ましたか。

+0

あなたは(get_ylimを使用して軸の範囲を得ることができます)とget_xlim()を呼び出して、探している線形関数の数式を計算します。 – Luka

+0

私は一直線の関数が直線の独立した線のみを必要としません – Manuel

+0

線形関数は直線の独立した線です。この方法は、matplotlibが選択する軸にのみ依存します。 – Luka

答えて

3

これは、散布図のデータから独立しており、ウィンドウのサイズを変更しても軸に根ざしたままその斜めの線を描画:

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.lines as mlines 
import matplotlib.transforms as mtransforms 

x, y = np.random.random((2, 100))*2 
fig, ax = plt.subplots() 
ax.scatter(x, y, c='black') 
line = mlines.Line2D([0, 1], [0, 1], color='red') 
transform = ax.transAxes 
line.set_transform(transform) 
ax.add_line(line) 
plt.show() 

enter image description here

+0

私が探していたものを試してみましょう! – Manuel

関連する問題