0

graph

how do I make this graph infill all the square around it? (I colored the part that I want to take off in yellow, for reference)

2 Answers 2

1

Normally I use two methods to adjust axis limits depending on a situation.

When a graph is simple, axis.set_ylim(bottom, top) method is a quick way to directly change y-axis (you might know this already).

Another way is to use matplotlib.ticker. It gives you more utilities to adjust axis ticks in your graph. https://matplotlib.org/3.1.1/gallery/ticks_and_spines/tick-formatters.html

I'm guessing you're using a list of strings to set yaxis tick labels. You may want to set locations (float numbers) and labels (string) of y-axis ticks separatedly. Then set the limits on locations like the following snippet.

import matplotlib.pyplot as plt
import matplotlib.ticker as mt

fig, ax = plt.subplots(1,1)
ax.plot([0,1,2], [0,1,2])
ax.yaxis.set_major_locator(mt.FixedLocator([0,1,2]))
ax.yaxis.set_major_formatter(mt.FixedFormatter(["String1", "String2", "String3"]))
ax.set_ylim(bottom=0, top=2)

It gives you this: generated figure

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

Comments

0

Try setting the min and max of your x and y axes.

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.