0

I am using the python code below to attempt to create a graph that fills the entire figure. The problem is I need the graph portion to stretch to fill the entire figure, there should not be any of the green showing and the graphed data should start at one side and go all the way to the other. I have found similar examples online but nothing that exactly solves my problem and I a matplotlib noob. Any help is greatly appreciated.

import numpy as np
import matplotlib.pyplot as plt

data = np.fromfile("rawdata.bin", dtype='<u2')
fig, ax = plt.subplots()
fig.patch.set_facecolor('xkcd:mint green')
ax.axes.xaxis.set_ticks([])
ax.axes.yaxis.set_ticks([])
ax.plot(data)
fig.tight_layout()
plt.show()

bad graph

2 Answers2

1

You can use subplots_adjust which gives you full control instead of tight_layout:

plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
Julien
  • 13,986
  • 5
  • 29
  • 53
  • Thank you very much that did pretty much what I needed I just need to look at setting the x limit so that the plot started on 0 to get rid of the excess space at the beginning of the plot. – user2231017 Oct 05 '21 at 02:26
1

If your environment is a Jupyter environment, you will see the margins even if you control the axes. To suppress this, please add the following code. This information was referenced from this answer. If you are in a normal environment, you can do this by controlling the axes.

import matplotlib.pyplot as plt
import numpy as np
%config InlineBackend.print_figure_kwargs = {'bbox_inches':None} # jupyter environment add

fig, ax = plt.subplots()
ax = fig.add_axes((0, 0, 1, 1), facecolor='gray') # update
ax.plot([1, 2, 3, 4], [1, 4, 2, 3])
fig.patch.set_facecolor('xkcd:mint green')
ax.axes.xaxis.set_ticks([])
ax.axes.yaxis.set_ticks([])

# fig.tight_layout()
plt.show()

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32