Skip to content
Snippets Groups Projects
Commit 166e65f7 authored by Martin Sauter's avatar Martin Sauter
Browse files

* changed dpi of plots

* changed size of plots
* changed location of legend in plots
parent bea983c1
Branches
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ def set_general_style(n_colors=11):
def plot_1d_hist(data_frame_list, weights_list, label_list, title='', x_label='', y_label='', x_log=False, y_log=False,
show_plot=True, save_plot=True, legend_loc='best', style='step', export_as='.pdf'):
show_plot=True, save_plot=True, legend_loc='center left', style='step', export_as='.pdf', dpi=500):
print('###################################################################################################')
print('Plotting: '+title)
print('---------------------------------------------------------------------------------------------------')
......@@ -50,21 +50,25 @@ def plot_1d_hist(data_frame_list, weights_list, label_list, title='', x_label=''
plt.xscale('log')
if y_log:
plt.yscale('log')
legend = ax1.legend(loc=legend_loc, numpoints=1, frameon=True, framealpha=1.0)
legend.get_frame().set_facecolor('white')
plt.title(title)
box = ax1.get_position()
ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax1.legend(loc=legend_loc, framealpha=1.0, numpoints=1, frameon=True, bbox_to_anchor=(1, 0.5))
fig.suptitle(title, fontsize=12)
fig.set_size_inches(8, 4.5)
if show_plot:
plt.show()
if save_plot:
fig.savefig('plots/' + title.replace(' ', '_') + export_as)
fig.savefig('plots/' + title.replace(' ', '_') + export_as, dpi=dpi)
plt.close()
return
def plot_2d_line(x_array_list, y_array_list, label_list, title='', x_label='', y_label='', x_log=False, y_log=False,
show_plot=True, save_plot=True, style='', export_as='.pdf'):
show_plot=True, save_plot=True, style='', export_as='.pdf', dpi=500):
print('###################################################################################################')
print('Plotting: '+title)
print('---------------------------------------------------------------------------------------------------')
......@@ -98,21 +102,26 @@ def plot_2d_line(x_array_list, y_array_list, label_list, title='', x_label='', y
if y_log:
plt.yscale('log')
if not label_list[0] == '':
legend = ax1.legend(loc='best', numpoints=1, frameon=True, framealpha=1.0)
legend.get_frame().set_facecolor('white')
plt.title(title)
# legend = ax1.legend(loc='best', numpoints=1, frameon=True, framealpha=1.0)
# legend.get_frame().set_facecolor('white')
box = ax1.get_position()
ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax1.legend(loc='center left', framealpha=1.0, numpoints=1, frameon=True, bbox_to_anchor=(1, 0.5))
fig.suptitle(title, fontsize=12)
fig.set_size_inches(8, 4.5)
if show_plot:
plt.show()
if save_plot:
fig.savefig('plots/' + title.replace(' ', '_') + export_as)
fig.savefig('plots/' + title.replace(' ', '_') + export_as, dpi=dpi)
plt.close()
return
def plot_2d_error(x_array_list, y_array_list, x_std_array_list, y_std_array_list, label_list, title='', x_label='',
y_label='', x_log=False, y_log=False, show_plot=True, save_plot=True, export_as='.pdf'):
y_label='', x_log=False, y_log=False, show_plot=True, save_plot=True, export_as='.pdf', dpi=500):
print('###################################################################################################')
print('Plotting: '+title)
print('---------------------------------------------------------------------------------------------------')
......@@ -130,21 +139,25 @@ def plot_2d_error(x_array_list, y_array_list, x_std_array_list, y_std_array_list
if y_log:
plt.yscale('log')
if not label_list[0] == '':
legend = ax1.legend(loc='best', numpoints=1, frameon=True, framealpha=1.0)
box = ax1.get_position()
ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height])
legend = ax1.legend(loc='center left', framealpha=1.0, numpoints=1, frameon=True, bbox_to_anchor=(1, 0.5))
legend.get_frame().set_facecolor('white')
plt.title(title)
fig.suptitle(title, fontsize=12)
fig.set_size_inches(8, 4.5)
if show_plot:
plt.show()
if save_plot:
fig.savefig('plots/' + title.replace(' ', '_') + export_as)
fig.savefig('plots/' + title.replace(' ', '_') + export_as, dpi=dpi)
plt.close()
return
def plot_2d_scatter_old(data_frame_list, label_list, x='', y='', title='', x_label='', y_label='', x_log=False,
y_log=False, show_plot=True, save_plot=True, export_as='.pdf'):
y_log=False, show_plot=True, save_plot=True, export_as='.pdf', dpi=500):
print('###################################################################################################')
print('Plotting: '+title)
print('---------------------------------------------------------------------------------------------------')
......@@ -169,19 +182,21 @@ def plot_2d_scatter_old(data_frame_list, label_list, x='', y='', title='', x_lab
plt.yscale('log')
legend = ax1.legend(loc='best', numpoints=1, frameon=True, framealpha=1.0)
legend.get_frame().set_facecolor('white')
plt.title(title)
fig.suptitle(title, fontsize=12)
fig.set_size_inches(8, 4.5)
if show_plot:
plt.show()
if save_plot:
fig.savefig('plots/' + title.replace(' ', '_') + export_as)
fig.savefig('plots/' + title.replace(' ', '_') + export_as, dpi=dpi)
plt.close()
return
def plot_2d_kde(data_frame, x='', y='', title='', x_label='', y_label='', x_log=False, y_log=False, show_plot=True,
save_plot=True, style='kde', export_as='.pdf'):
save_plot=True, style='kde', export_as='.pdf', dpi=500):
print('###################################################################################################')
print('Plotting: '+title)
print('---------------------------------------------------------------------------------------------------')
......@@ -204,14 +219,14 @@ def plot_2d_kde(data_frame, x='', y='', title='', x_label='', y_label='', x_log=
if show_plot:
plt.show()
if save_plot:
sns_plot.savefig('plots/' + title.replace(' ', '_') + export_as)
sns_plot.savefig('plots/' + title.replace(' ', '_') + export_as, dpi=dpi)
plt.close()
return
def plot_2d_matrix(data_frame, x='', y='', title='', x_label='', y_label='', x_log=False, y_log=False, show_plot=True,
save_plot=True, export_as='.pdf'):
save_plot=True, export_as='.pdf', dpi=500):
print('###################################################################################################')
print('Plotting: '+title)
print('---------------------------------------------------------------------------------------------------')
......@@ -242,14 +257,14 @@ def plot_2d_matrix(data_frame, x='', y='', title='', x_label='', y_label='', x_l
if show_plot:
plt.show()
if save_plot:
sns_plot.savefig('plots/' + title.replace(' ', '_') + '_matrix.png')
sns_plot.savefig('plots/' + title.replace(' ', '_') + '_matrix.' + export_as, dpi=dpi)
plt.close()
return
def plot_2d_scatter(data_frame_list, label_list, x='', y='', title='', x_label='', y_label='',
x_log=False, y_log=False, show_plot=True, save_plot=True, export_as='.pdf'):
x_log=False, y_log=False, show_plot=True, save_plot=True, export_as='.pdf', dpi=500):
print('###################################################################################################')
print('Plotting: '+title)
print('---------------------------------------------------------------------------------------------------')
......@@ -362,12 +377,27 @@ def plot_2d_scatter(data_frame_list, label_list, x='', y='', title='', x_label='
ax1.yscale('log')
legend = ax1.legend(loc='best', numpoints=1, frameon=True, framealpha=1.0)
legend.get_frame().set_facecolor('white')
# play with this factor ot ensure a better design, as well as the distance_between_ax1_ax3
shrink_factor = 0.75
distance_between_ax1_ax3 = 1.1
box1 = ax1.get_position()
ax1.set_position([box1.x0, box1.y0, box1.width * shrink_factor, box1.height])
box2 = ax2.get_position()
ax2.set_position([box2.x0, box2.y0, box2.width * shrink_factor, box2.height])
box3 = ax3.get_position()
ax3.set_position([box3.x0 - box1.width * (1 - shrink_factor), box3.y0, box3.width * shrink_factor, box3.height])
legend = ax1.legend(loc='center left', framealpha=1.0, numpoints=1, frameon=True,
bbox_to_anchor=((distance_between_ax1_ax3 + box1.width) * shrink_factor, 0.5))
legend.get_frame().set_facecolor('white')
fig.suptitle(title, fontsize=12)
fig.set_size_inches(8, 4.5)
if show_plot:
plt.show()
if save_plot:
fig.savefig('plots/' + title.replace(' ', '_') + export_as)
fig.savefig('plots/' + title.replace(' ', '_') + export_as, dpi=dpi)
plt.close()
return
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment