1

I have a file that combines data sets from different sources but preserves the common format. I want to plot these using different colors to indicate the different sources of the data sets. For example, a few lines in the data file look like this:

# Source measurement1 measurement2 error color
SiteA  543.2 12.3 0.01 blue
SiteB  545.6 12.5 0.02 red
SiteA  545.9 12.9 0.01 blue
SiteC  549.1 13.2 0.01 orange
SiteB  550.4 13.3 0.02 red
...

At the moment I do a for loop and plot each point:

for point in data:
   plt.errorbar(measurement1,measurement2,yerr=error, marker='.', ecolor='k', fmt=color, linestyle='.')

This plots each point individually but can take a very long time for large data arrays.

Can anyone suggest a faster way of doing it?

1 Answer 1

2

If you don't have too many colours, you should be able to speed things up by plotting in groups of colours, i.e. calling pyplot.errorbar() once for each colour. Use list comprehension to group the data into colour groups, and provide lists or arrays instead of scalars for measurement1, measurement2 etc.

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

1 Comment

Hi wim,thanks for the answer. I have about 30 colors so your suggestion will probably work fine. I'll try it out and compare the speed of execution. I was wondering whether using numpy arrays might be a faster option.

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.