matplotlib - drawing line on scatter graph in python -


i have code plots data points on scatter graph , draws 2 lines on it. want lines go edge of plot create box in top left corner containing of data points. however, plot adds space beyond end of lines have 2 lines @ right angles rather box. know how stop adding space, horizontal line goes y axis , vertical line top of plot, creating box?

my code

import pyfits import numpy np import math numpy.lib import scimath scimath.log(-math.exp(1)) == (1+1j*math.pi) import matplotlib.pyplot plt  ###---colour colour plots  path2 = "/data/nhine/colour_plots/"   ##my data hdulist = pyfits.open(path2 + 'colour_plots_z1_final.fits') hdulist1 = pyfits.open(path2 + 'colour_plots_z1_5_final.fits') hdulist2 = pyfits.open(path2 + 'colour_plots_z5_final.fits')  table = hdulist[1] table1 = hdulist1[1] table2 = hdulist2[1]  col1_1 = np.array(table.data.field('col1'))  #kab - irac1 col2_1 = np.array(table.data.field('col2'))  #hab - kab col3_1 = np.array(table.data.field('col3'))  #redmag col4_1 = np.array(table.data.field('col4'))  #irac1-irac2 col1_15 = np.array(table1.data.field('col1')) col2_15 = np.array(table1.data.field('col2')) col3_15 = np.array(table1.data.field('col3')) col4_15 = np.array(table1.data.field('col4')) col1_5 = np.array(table2.data.field('col1')) col2_5 = np.array(table2.data.field('col2')) col3_5 = np.array(table2.data.field('col3')) col4_5 = np.array(table2.data.field('col4'))  ##lines x = np.array([1.6,1.6,1.6,1.6,1.6,1.6,]) y = np.array([2.15,2.25,2.4,2.5,2.6,2.7,]) w = np.array([0.7,0.8,1.0,1.2,1.4,1.6]) z = np.array([2.15,2.15,2.15,2.15,2.15,2.15])  ##c12 data  qso6a = np.array([1.5]) qso6b = np.array([2.25]) gal6a  = np.array([0.7]) gal6b  = np.array([2.4]) all35a  = np.array([1.5,1.16,1.8,2.4,2.55,2.6,2.7,2.78,2.9]) all35b  = np.array([2,1.6,1.9,1.35,0.9,1.25,1.65,1.1,1.3]) less1a  = np.array([2.4,2.9,3.3,3.309]) less1b  = np.array([1.3,0.7,1.75,1.35])  ##plot  pylab import *   fig = figure() ax1 = fig.add_subplot(111)  ax1.scatter(col2_5, col1_5, s=50, c='g', marker="s", label='targets @ z>5') ax1.scatter(gal6a, gal6b, s=50, c='g', marker="o", label='c12 galaxy @ z~6') ax1.scatter(qso6a, qso6b, s=50, c='g', marker="d", label='c12 qso @ z~6') ax1.scatter(col2_15, col1_15, s=50, c='r', marker="s", label='targets @ 1<z<5') ax1.scatter(all35a, all35b, s=50, c='r', marker="o", label='c12 @ 3<z<5') ax1.scatter(col2_1, col1_1, s=50, c='b', marker="s", label='targets @ z<1') ax1.scatter(less1a, less1b, s=50, c='b', marker="o", label='c12 z<1')  plot(x,y, color='b') plot(w,z, color='b') legend(loc='best', numpoints=1, ncol=1, fontsize=8) ttext = title('colour-colour plot') ytext = ylabel('k - irac1') xtext = xlabel('h - k') setp(ttext, size='large', color='black', style='italic') setp(xtext, size='medium', weight='light', color='black') setp(ytext, size='medium', weight='light', color='black') show()  hdulist.close() hdulist1.close() hdulist2.close() 

you can prevent axes being rescaled when draw 'box' using plot(...,scalex=false,scaley=false).

however, suggest use rectangle outline points, e.g.:

from matplotlib.pyplot import rectangle mybox = rectangle((0.7,2.15), 0.9, 0.55, fill=false, ec='b') ax1.add_artist(mybox) 

or else take @ matplotlib's tools annotation include various fancy boxes , arrows.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -