I wrote a Python code for generating a hexbin
plot and I would like to save it in a image file but it's impossible, the code creates a file but with nothing inside.
import pandas as pd
import matplotlib.pyplot as plt
output_report = 'H:\_JUPYTER\_report\\'
df = pd.read_csv('H:\\_JUPYTER\\_report\\matrix_delta_speed.csv.bz2', compression='bz2', index_col='date', parse_dates=['date'], date_parser=lambda col: pd.to_datetime(col, errors='coerce'))
x = df.speed
y = df.delta
fig, ax = plt.subplots(ncols=1, sharey=True, figsize=(17, 10))
hb = ax.hexbin(x, y, gridsize=(150,150), cmap='inferno')
ax.axis([x.min(), x.max(), y.min(), y.max()])
ax.set_title('Delta vs. Speed')
ax.set_xlabel('Speed')
ax.set_ylabel('Delta')
cb = fig.colorbar(hb, ax=ax)
cb.set_label('counts')
plt.show()
plt.savefig(output_report+'Matrix.png', dpi=600)
I process to savefig
but the file is completely white:
It's the same case for "hist" and other plot.