1

I want to work with a scatter plot within a FigureCanvasQTAgg. The scatter plot may have 50,000 or more data points. The user wants to draw a polygon in the plot to select the data points within the polygon. I've realized that by setting points via mouse clicks and connect them with lines using Axis.plot(). When the user has set all points the polygon is drawn. Each time I add a new point I call FigureCanvasQTAgg.draw() to render the current version of the plot. This is slow, because the scatter plot has so much data. Is there a way to make this faster?

8
  • You should decimate your data points before drawing them in the scatter plot. If decimation is not possible, then you should only show the region where the user wants to draw the polygon. This should speed up your rendering. Commented Mar 7, 2017 at 19:47
  • 4
    There are 409 questions for matplotlib "slow" and 354 for matplotlib "faster". Does none of them help? In that case, be more specific and tell us what you have tried and why it didn't help. Commented Mar 7, 2017 at 19:47
  • why do you need that many data points? what's the end goal of this code? Commented Mar 7, 2017 at 19:55
  • @MohammadAthar the goal is to cut out certain points and write the reminder to a file. This is done easiest by visual inspection. Commented Mar 7, 2017 at 20:10
  • 1
    Not providing the necessary code and not narrowing down the scope of the question simply lowers the chances of getting a satisfying answer. At the end, it's your choice. Personnally, I find it very unsatifactory to write a complete minimal example and do the reseach myself, thereby spending more time than the questioner on the solution. Commented Mar 9, 2017 at 12:59

2 Answers 2

1

Two possible solutions:

  1. Don't show a scatter plot, but a hexbin plot instead.
  2. Use blitting.

(In case someone wonders about the quality of this answer; mind that the questioner specifially asked for this kind of structure in the comments below the question.)

Sign up to request clarification or add additional context in comments.

1 Comment

Interesting idea, but I do have more than one colour. How about that: (I put it inot a seperate answer)
0

I can try to convert the scatter plot into an image using matplotlib to render it and display the image with imshow:

import matplotlib
matplotlib.use('QT4AGG')
import matplotlib.pyplot as plt
import Image # PIL
from io import BytesIO
from matplotlib import image

plt.scatter(xdata, ydata)
plt.axis('off')
plt.subplots_adjust(0, 0, 1, 1, 0, 0)
stream = BytesIO()
plt.savefig(stream, format='raw')
pilImage = Image.fromstring('RGBA',size=(640, 480), data = stream.getvalue())
plt.imshow(image.pil_to_array(pilImage))

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.