Adding line to scatter plot using python's matplotlib -
i using python's matplotlib , want create matplotlib.scatter() additional line. line should proceed lower left corner upper right corner independent of scatters content. linear regression through data, in this post, not looking for. should dynamically , independent of scatter input.
this should final plot:
edit:
doing got me result:
# 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() is there better way ?
this draws diagonal line independent of scatter plot data , stays rooted axes if resize window:
import numpy np import matplotlib.pyplot plt import matplotlib.lines mlines import matplotlib.transforms 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() 

Comments
Post a Comment