Often when I am learning new machine learning methods or experimenting with a data analysis algorithm I need to generate a series of 2D points. Teachers also do this often when making a lesson or tutorial.

In some cases I just create a function, add some noise, and plot it, but there are many times when I wish I could just click my mouse on a graph to generate points. For instance, when I want to generate a fairly complex relationship between x and y, it's a hassle to think of the right formulation to generate the points programmatically.

Does there exist a tool that will allow me to generate data points using my mouse, with an option to export to CSV (or other simple format)?

For example, I am currently learning how to use mutual information and entropy as a metric of dependence between variables. I'd like to see what happens when I have data that is clearly dependent but does not have a linear relationship, so I drew this image:

Non-linear dependence

Now I just need a way to export the coordinates of the points to CSV. I realize this is a simple program and I could write my own, but surely someone has already done this and created a tool to do so? It could be a website, an .exe, Python source, or any other application.


5 Answers 5



I think this one also good, the highest vote one, you have to click one by one to generate more data points, this one is much faster...

enter image description here

  • $\begingroup$ I like how fast it is to draw many points. One downside: can't draw single points if you wanted. $\endgroup$
    – MD004
    Commented Jul 31, 2023 at 21:06

I recently discovered this site: https://guoguibing.github.io/librec/datagen.html

Outputs list of points, and color ID (class) for each point.

Screenshot: Datagen screenshot

  • $\begingroup$ In Python, one can convert the output from this website to a Pandas Dataframe using points = pandas.read_csv(io.BytesIO(pointsTxt), sep='\n', delimiter=',', names=['x','y','class']) $\endgroup$
    – MD004
    Commented Apr 7, 2017 at 18:16
  • $\begingroup$ Sadly, this website is no longer online :( $\endgroup$
    – MD004
    Commented Dec 24, 2020 at 1:15
  • $\begingroup$ ...but I found a working link and have updated the link above. $\endgroup$
    – MD004
    Commented Jan 6, 2022 at 19:28

In R:

First set up a blank plot with whatever x and y scale limits you need:

plot(NA, xlim=c(11,20),ylim=c(10,99))

Then click click click with mouse-button 1 and end with mouse-button 2 (probably):

pts = data.frame(locator(type="p"))

Then save as a CSV file:



  • $\begingroup$ Still need a way to add classes $\endgroup$
    – 27px
    Commented Oct 3, 2023 at 11:37

I found a simple Python solution, adapted from https://stackoverflow.com/q/25521120/1265192

This also works in a Jupyter Notebook, if desired.

import numpy as np
import matplotlib.pyplot as plt

%matplotlib qt

fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111)


coords = []

def onclick(event):
    x, y = event.xdata, event.ydata

    global coords
    coords.append((x, y))

    ax.scatter([x], [y], c='b', s=150)
cid = fig.canvas.mpl_connect('button_press_event', onclick)


The coordinates are stored in coords and also printed to the screen (but with 1 decimal place). One could save the coordinates to a file, but I just copy/paste the printed coordinates wherever I want them.


Just updating the other answers.

You could use this site: https://guoguibing.github.io/librec/datagen.html

to make it a dataframe:

points = pd.read_csv('/content/pontos.csv', sep='\n', delimiter=',', names=['x','y','class'])

enter image description here

  • $\begingroup$ Thanks for posting! However, one of the other answers already suggested this tool. Oh! But I see you found a URL that works, whereas the other answer has a broken link. We can edit that answer with the new link. $\endgroup$
    – MD004
    Commented Sep 30, 2021 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.