Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1D plot matplotlib

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

like image 358
Alejandro D. Somoza Avatar asked May 08 '14 15:05

Alejandro D. Somoza


People also ask

What is a 1D plot?

1D Plots - (one-dimensional) plots allow you to display one parameter of your data. You can also display a cumulative probability distribution of your data.

How do you make a one direction plot in Python?

The quickest way to generate a simple, 1-D plot is using the pyplot. plot() function. the figure and axis objects and plots the data onto them. the figure and axes objects automatically, and is the simplest way to create a plot.

How do I plot a straight line in Matplotlib?

To plot a line plot in Matplotlib, you use the generic plot() function from the PyPlot instance.


1 Answers

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

like image 60
Molly Avatar answered Sep 30 '22 20:09

Molly