Uddeshya Singh Uddeshya Singh - 3 months ago 8
Python Question

Plotting a graph in python

I'm new to python and want to plot a point on graph in python..

X_cord=int(raw_input("Enter the x-coordinate"))
Y_cord=int(raw_input("Enter the y-coordinate"))

I could just figure out this much.


Have a look at matplotlib, a 2D plotting library for Python. For your code, this could work:

import matplotlib.pyplot as plt # I include a module which contains the plotting functionality I need: https://docs.python.org/2/tutorial/modules.html
plt.plot(X_cord,   # here go the X coordinates
         Y_cord,   # here go the Y coordinates
         marker='x', # as I'm plotting only one point here, I'd like to make it extra visible
         markersize=10 # by choosing a nice marker shape ('x') and large size
plt.show() # this shows the current plot in a pop-up window

If you would like to immediately save the figure as an image, you can also choose to replace the last line by

plt.savefig("my_first_plot.pdf", bbox_inches='tight')

Edit: I spelled it out a bit more, but the main suggestion is to get to know Python better (ample tutorials on the web, this is not the place for it) and to read the matplotlib documentation if you want to know more about plotting. Hope this helps, or feel free to post specific problems you are having.