Question

I would like to plot in a single line ticks according to an array (up to 1000 elements). I would rather not to use something like:

    plt.xticks(energies[i][j])

because each sample value is written up below tick. I have looked extensively at Matplotlib documentation but didn't find nothing besides hist(). If you guys know other way to visualize 1D arrays into a single line I would very much appreciate, especially if it involves colors representing density of values.

I'm using Spyder 2.2.5, Python 2.7.6 | 64-bit in OSX 10.7.4

Was it helpful?

Solution

Edit As @tcaswell mentions in comments, eventplot is a good way to do this. Here is an example:

from matplotlib import pyplot as plt
import numpy as np

plt.figure()
a = [1,2,5,6,9,11,15,17,18]
plt.hlines(1,1,20)  # Draw a horizontal line
plt.eventplot(a, orientation='horizontal', colors='b')
plt.axis('off')
plt.show()

enter image description here

Or you can use vertical line markers? The example below has the basic idea. You could change the color of the markers to represent density.

from matplotlib import pyplot as plt
import numpy as np

a = [1,2,5,6,9,11,15,17,18]

plt.hlines(1,1,20)  # Draw a horizontal line
plt.xlim(0,21)
plt.ylim(0.5,1.5)

y = np.ones(np.shape(a))   # Make all y values the same
plt.plot(a,y,'|',ms = 40)  # Plot a line at each location specified in a
plt.axis('off')
plt.show()

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top