1

I have some code:

def print_fractures(fractures):
    # generate ends for the line segments
    xpairs = []
    ypairs = []
    plt.subplot(132)

    for i in range(len(fractures)):
        xends = [fractures[i][1][0], fractures[i][2][0]]
        yends = [fractures[i][1][1], fractures[i][2][1]]
        xpairs.append(xends)
        ypairs.append(yends)
    for xends,yends in zip(xpairs,ypairs):
        plt.plot(xends, yends, 'b-', alpha=0.4)
        plt.plot()
    plt.xlabel("X Coordinates (m)")
    plt.ylabel("Y Coordinates (m)")
    plt.ylim((0,400))


def histogram(spacings):
    plt.subplot(131)
    plt.hist(np.vstack(spacings), bins = range(0,60,3), normed=True)
    plt.xlabel('Spacing (m)')
    plt.ylabel('Frequency (count)')
    #plt.title("Fracture Spacing Histogram")


def plotCI(sample, ciHigh, ciLow, avgInts):
    plt.subplot(133)    
    plt.plot(sample,ciHigh)
    plt.plot(sample,avgInts)
    plt.plot(sample,ciLow)
    plt.legend(['Mean + 95% CI', 'Mean', 'Mean - 95% CI'])
    plt.title("Intersections vs Number of Wells")
    plt.xlabel("# of Wells")
    plt.ylabel("# of Intersections for " + str(bedT) + "m bed thickness")

def makeplots(spacings,fractures): 
    histogram(spacings)
    print_fractures(fractures)
    plt.axis('equal')
    plotCI(sample, ciHigh, ciLow, avgInts)
    plt.show()
makeplots(spacings,fractures)

The code produces the following plot: enter image description here

As you can see, in the center plot, the plot is not really centered... I would like to set the x and y axes to (0,400) but I am having troubles.

So far I have tried:

plt.axis((0,400,0,400))

and:

plt.ylim((0,400))
plt.xlim((0,400))

Neither option worked for me.

3
  • Did you try plt.axis("tight") ? Commented Jan 31, 2014 at 20:05
  • That also does not work. In any case, I really want to be able to set the axis limits... Maybe it would look better from -50,450 - creating a bit of whitespace around the lines, for example. Commented Jan 31, 2014 at 20:08
  • Could you try cs=plt.plot(xends, yends, 'b-', alpha=0.4); cs.axis("tight") and remove the extra plt.plot() and see if that helps. Commented Jan 31, 2014 at 21:03

1 Answer 1

2

In your example, it is not shown how / when the functions are called. There are some possible side effects concerning plt.ion()/plt.ioff() and the focus of your actual plot at the time of executing xlim()/ylim() commands.

To have full control (especially, when having more than one plot), it is usually better to have explicit figure and plot handles, e.g:

fg = plt.figure(1)
fg.clf()  # clear figure, just in case the script is not executed for the first time 
ax1 = fg.add_subplot(2,1,1)
ax1.plot([1,2,3,4], [10,2,5,0])
ax1.set_ylim((0,5)) # limit yrange

ax2 = fg.add_subplot(2,1,2)    
...

fg.canvas.draw()  # the figure is drawn at this point

plt.show()  # enter GUI event loop, needed in non-interactive interpreters
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.