0

I need my plots to completely fill with color. Adjusting xlim, ylim, only works works after, but it is apparently past the step where the plot is completely filled. In cases where data spans (0,360), (90,180), the fill is fine, but if the data is tighter, white space is present.

They also need to all have the same axis limits, so they can be compared visually, so just letting it stay in auto mode isn't going to work.

I'm considering and working on just trying to work on the background color of the plot area, but that is still behaving problematic when saving to a png.

(Note: my filled example still has a sliver missing at the bottom)

import matplotlib.pyplot as plt
import numpy as np

X = []
Y = []

X, Y = np.loadtxt('dihedral.txt', delimiter=',', unpack=True)

plt.hist2d(X, Y, bins=200, cmap='jet')
cb = plt.colorbar()
cb.set_label('counts in bin')

plt.ylim(90, 180) 
plt.xlim(0, 360)

plt.title('title')
plt.xlabel('dihedral angle')
plt.ylabel('angle of bend')
#plt.show()

plt.savefig('dihedral.png', dpi=300)

unfilled plot

desired example of filled plot

Josh
  • 11
  • 3

1 Answers1

0

I just ran into same issue. Solution is to set hist2d 'range' parameter to match xlim and ylim. In your case,

plt.hist2d(X, Y, bins=200, cmap='jet', range=[[0,360],[90,180]])
  • Thank you! That worked. I had tried something similar, but got errors and thought it was something else to do with bin size – Josh Aug 17 '22 at 23:51