0

I've got a graph plotted using the matplotlib library, and would like to know if there is a way to view from a custom range. I have several vertical lines, starting 0. The beginning of the plot also starts at zero and makes seeing that first line difficult. Is there a way that I can have a view window starting a little more to the left (even though there is no value associated to it)? I know that it was possible in Mathematica with PlotRange, but I don't see an equivalent for `matplotlib'.

I've tried playing with the example found on:

http://matplotlib.org/examples/pylab_examples/vline_hline_demo.html

import matplotlib.pyplot as plt
import numpy as np
import numpy.random as rnd

def f(t):
    s1 = np.sin(2 * np.pi * t)
    e1 = np.exp(-t)
    return np.absolute((s1 * e1)) + .05

t = np.arange(0.0, 5.0, 0.1)
s = f(t)
nse = rnd.normal(0.0, 0.3, t.shape) * s

fig = plt.figure(figsize=(12, 6))
vax = fig.add_subplot(121)
vax.vlines(t, [0], s)

plt.show()

but can't the plot to display empty space to the left (or right)

1 Answer 1

1

Use plt.xlim (or plt.ylim)

import matplotlib.pyplot as plt import numpy as np import numpy.random as rnd

def f(t):
    s1 = np.sin(2 * np.pi * t)
    e1 = np.exp(-t)
    return np.absolute((s1 * e1)) + .05

t = np.arange(0.0, 5.0, 0.1)
s = f(t)
nse = rnd.normal(0.0, 0.3, t.shape) * s

fig = plt.figure(figsize=(12, 6))
vax = fig.add_subplot(121)
vax.vlines(t, [0], s)

plt.xlim(-0.2,5.2)

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.