开发者

Python matplotlib plotting an array with different colors

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 a开发者_StackOverflowrrays.

Can anyone suggest a faster way of doing it?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜