Skip to content

Commit beb56e9

Browse files
authored
Merge pull request #15383 from johodges/fdsplotlib
Add some functionality to fdsplotlib kwargs and update a few defaults for better viewing at a distance.
2 parents ca176d8 + f1bb29e commit beb56e9

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

Utilities/Python/fdsplotlib.py

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,8 @@ def plot_to_fig(x_data,y_data,**kwargs):
502502
default_markevery = 1
503503
markerfacecolor = None
504504
markeredgecolor = 'black'
505-
markeredgewidth = 1
506505
marker = None
507-
markersize = 5
508506
linestyle = '-'
509-
linewidth = 1
510507
color = 'black'
511508
###############################
512509

@@ -576,10 +573,34 @@ def plot_to_fig(x_data,y_data,**kwargs):
576573

577574
error_fill_color = kwargs.get('error_fill_color',None)
578575

576+
# adjust sizes if requested
577+
linewidth = kwargs.get('linewidth',1)
578+
markeredgewidth = kwargs.get('markeredgewidth',1)
579+
markersize = kwargs.get('markersize',5)
580+
581+
# adjust ticks if required
582+
xnumticks = kwargs.get('xnumticks',None)
583+
ynumticks = kwargs.get('ynumticks',None)
584+
xticks = kwargs.get('xticks',None)
585+
yticks = kwargs.get('yticks',None)
586+
579587
# other plot parameters
580588
markevery = kwargs.get('data_markevery',default_markevery)
581589
legend_location = kwargs.get('legend_location',default_legend_location)
582590
legend_framealpha = kwargs.get('legend_framealpha',default_legend_framealpha)
591+
592+
# set dashes to default, or user requested
593+
# This set is the matplotlib default
594+
#if linestyle == '': dashes = (None, None); linewidth = 0;
595+
#if linestyle == '-': dashes = (None, None)
596+
#if linestyle == '--': dashes = kwargs.get('line_dashes',(6, 6))
597+
#if linestyle == '-.': dashes = kwargs.get('line_dashes',(6, 3, 1, 3))
598+
599+
# This set is what we were using in Matlab
600+
if linestyle == '': dashes = (None, None); linewidth = 0;
601+
if linestyle == '-': dashes = (None, None)
602+
if linestyle == '--': dashes = kwargs.get('line_dashes',(18.0, 11.1))
603+
if linestyle == '-.': dashes = kwargs.get('line_dashes',(12, 7.4, 3, 7.4))
583604

584605
data_label = kwargs.get('data_label',None)
585606

@@ -599,7 +620,8 @@ def plot_to_fig(x_data,y_data,**kwargs):
599620
markersize=markersize,
600621
linestyle=linestyle,
601622
linewidth=linewidth,
602-
color=color)
623+
color=color,
624+
dashes=dashes)
603625

604626
if plot_type=='loglog':
605627
ax.loglog(x_data,y_data,
@@ -612,7 +634,8 @@ def plot_to_fig(x_data,y_data,**kwargs):
612634
markersize=markersize,
613635
linestyle=linestyle,
614636
linewidth=linewidth,
615-
color=color)
637+
color=color,
638+
dashes=dashes)
616639

617640
if plot_type=='semilogx':
618641
ax.semilogx(x_data,y_data,
@@ -625,7 +648,8 @@ def plot_to_fig(x_data,y_data,**kwargs):
625648
markersize=markersize,
626649
linestyle=linestyle,
627650
linewidth=linewidth,
628-
color=color)
651+
color=color,
652+
dashes=dashes)
629653

630654
if plot_type=='semilogy':
631655
ax.semilogy(x_data,y_data,
@@ -638,7 +662,8 @@ def plot_to_fig(x_data,y_data,**kwargs):
638662
markersize=markersize,
639663
linestyle=linestyle,
640664
linewidth=linewidth,
641-
color=color)
665+
color=color,
666+
dashes=dashes)
642667

643668
# if y fill range is passed, add it to the plot
644669
if kwargs.get('y_error_fill_absolute') and not kwargs.get('y_error_fill_relative'):
@@ -762,6 +787,23 @@ def plot_to_fig(x_data,y_data,**kwargs):
762787

763788
ax.set_xlim(xmin,xmax)
764789
ax.set_ylim(ymin,ymax)
790+
791+
# set number of ticks if requested by the user
792+
if ynumticks != None:
793+
if plot_type in ('loglog', 'semilogx'):
794+
ax.set_xticks(np.logspace(xmin, xmax, xnumticks))
795+
else:
796+
ax.set_xticks(np.linspace(xmin, xmax, xnumticks))
797+
if ynumticks != None:
798+
if plot_type in ('loglog', 'semilogy'):
799+
ax.set_yticks(np.logspace(ymin, ymax, ynumticks))
800+
else:
801+
ax.set_yticks(np.linspace(ymin, ymax, ynumticks))
802+
803+
# set ticks if requested by the user
804+
if xticks is not None: ax.set_xticks(xticks)
805+
if yticks is not None: ax.set_yticks(yticks)
806+
765807

766808
if plot_type in ('loglog', 'semilogy'):
767809
apply_global_exponent(ax, axis='y', fontsize=axeslabel_fontsize)
@@ -772,6 +814,8 @@ def plot_to_fig(x_data,y_data,**kwargs):
772814
add_version_string(ax=ax, version_str=kwargs.get('revision_label'), plot_type=plot_type, font_size=version_fontsize)
773815

774816
# fig.tight_layout() # this should not be needed if figure_size and plot_size are both specified
817+
818+
set_ticks_like_matlab(fig)
775819

776820
return fig
777821

@@ -1685,3 +1729,12 @@ def statistics_histogram(Measured_Values, Predicted_Values,
16851729

16861730
print(f"[statistics_histogram] {Scatter_Plot_Title}: p = {pval:.2f}")
16871731
return f"{os.path.basename(Plot_Filename)}_Histogram", pval
1732+
1733+
def set_ticks_like_matlab(fig):
1734+
ax = fig.axes[0]
1735+
ax.tick_params(axis="both", direction="in", top=True, right=True, width=0.5)
1736+
1737+
for axis in ['top','bottom','left','right']:
1738+
ax.spines[axis].set_linewidth(0.5)
1739+
1740+

0 commit comments

Comments
 (0)