3

I am generating a pyplot using the following code:

plotCount = 1
for key in resultsDictionary:
  count = 1
  p1 = plt.subplot(5,1,plotCount)
  plotCount+=1
  for item in resultsDictionary[key]:
    print count , item , key
    plt.plot(item, count, marker='o')
    count+=1

The generated plot has the top and bottom results 'squashed' on the graph. How can I add some kind of padding to the top of the graph and size of the graph (or is it possible to set the exact size of the graph (I know the min/max values).

If anyone can point me in the right direction I'd appreciate it.

3 Answers 3

4

You might want to take a look at the tight_layout guide, which describes how to do this sort of thing automagically. This was only introduced recently (in version 1.1) though.

Alternatively, you get a lot more control if you use the add_axes command instead of subplot(), which allows you to set the relative position and size of each graph.

Sign up to request clarification or add additional context in comments.

Comments

2

I think you are asking about setting the limits of the graphs. You need to add

plt.set_xlim([xmin,xmax])
plt.set_ylim([ymin,ymax])

to your code in the outer loop (with sensible values for xmin,xmax,ymin,ymax).

Comments

0

Layout adjusts did not work for me, since the whole figure would just resize with the labels still squashed or out of bounds.

A workaround I found was to keep the y-axis always a certain margin over the highest or minimum y-values:

x1,x2,y1,y2 = plt.axis()
plt.axis((x1,x2,y1 - 100 ,y2 + 100))

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.