Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to draw a plot vertically with python matplotlib?

I need to draw a plot looks like this:

enter image description here

Is it possible? How can I do this?

like image 612
wtm Avatar asked May 21 '12 04:05

wtm


People also ask

How do you plot vertically in Python?

To plot a vertical line with pyplot, you can use the axvline() function. In this syntax: x is the coordinate for the x-axis. This point is from where the line would be generated vertically. ymin is the bottom of the plot; ymax is the top of the plot.


1 Answers

I don't know what is your data for ... but here is a 'vertical' plot of hypothetical oxygen levels in near sea surface...

Note that nothing special is required. Simply order your x and y values such that a line drawn from the first coordinate to the second and so on gives the vertical line you desire.

(The one special thing I've done here -- which may or may not be what you want -- is put the xticks at the top of the plot, using tick_top.)

import matplotlib.pyplot as plt

# define data

Oxygen = [ 0.1 , 0.5, 1, 10, 15, 20, 15, 10, 1, 0.5, 0.5]
Depth  = [ 0,     1,  2,  4,  8, 10, 12, 14, 16, 20, 40 ]

fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(Oxygen, Depth, 'go--')
ax.xaxis.tick_top()

ax.set_ylabel('depth')
ax.set_ylim(50, 0)
ax.set_xlim(0, 25)
ax.set_xlabel('Oxygen level [ppm]')

plt.show()

This yields: enter image description here

I hope it helps ...

like image 146
oz123 Avatar answered Sep 27 '22 21:09

oz123