I have to plot a large amount of data in python (a list of size 3 million) any method/libraries to plot them easily since matplotlib does not seem to work.
CodePudding user response:
what do you mean matplotlib does not work? It works when I tried it. is your data 1-dimensional or multi-dimensional? Are you expecting to see 3 million ticks in x axis? because that would not be possible.
d = 3*10**6
a = np.random.rand(d)
a[0] = 5
a[-1] = -5
print(a.shape)
plt.plot(a)
CodePudding user response:
I use quite intensively matplotlib in order to plot arrays of size n > 10**6.
You can use plt.xscale('log')
which allow you to display your results.
Furthermore, if your dataset shows great disparity in value, you can use plt.yscale('log')
in order to plot them nicely if you use the plt.plot()
function.
If not (ie you use imshow, hist2d and so on) you can write this in your preamble :
from matplotlib.colors import LogNorm
and just declare the optional argument norm = LogNorm()
.
One last thing : you shouldn't use numpy.loadtxt
if the size of the text file is greater than your available RAM. In that case, the best option is to read the file line by line, even if it take more time. You can speed up the process with from numba import jit
and declare @jit(nopython=True, parallel =True)
.
With that in mind, you should be able to plot in a reasonably short time array of size of about ten millions.