Skip to content

Commit

Permalink
Merge pull request #5 from petersbingham/chart-options
Browse files Browse the repository at this point in the history
Add additional chart configuration options.
  • Loading branch information
petersbingham authored Jan 26, 2019
2 parents deb9223 + 2eae3b8 commit df5456c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
30 changes: 24 additions & 6 deletions matfuncutil/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __init__(self, d=None, x_units=None, y_units=None, chart_title="",
self.use_marker = False
self.xsize = None
self.ysize = None
self.dashes = None
self.cycle_dashes = False
self.dpi = 300

self.sig_figs = 6
self.source_str = source_str
Expand Down Expand Up @@ -188,7 +191,8 @@ def set_axis_labels(self, x_plotlbl, y_plotlbl=""):
self.y_plotlbl = y_plotlbl

def set_chart_parameters(self, colour_cycle=None, leg_prefix=None,
use_marker=None, xsize=None, ysize=None):
use_marker=None, xsize=None, ysize=None,
dashes=None, cycle_dashes=False, dpi=300):
if colour_cycle is not None:
self.colour_cycle = colour_cycle
if leg_prefix is not None:
Expand All @@ -199,6 +203,10 @@ def set_chart_parameters(self, colour_cycle=None, leg_prefix=None,
self.xsize = xsize
if ysize is not None:
self.ysize = ysize
if dashes is not None:
self.dashes = dashes
self.cycle_dashes = cycle_dashes
self.dpi = dpi

def set_print_parameters(self, sig_figs):
self.sig_figs = sig_figs
Expand All @@ -210,7 +218,7 @@ def plot(self, logx=False, logy=False, imag=False, show=True,
save_path=None, add_axis_lmts=False):
fig,plt = self._plot(logx, logy, imag)
if save_path is not None:
plt.savefig(save_path, bbox_inches='tight')
plt.savefig(save_path, bbox_inches='tight', dpi=self.dpi)
if show:
if save_path is not None:
set_plot_paths(fig, save_path, add_axis_lmts)
Expand All @@ -228,6 +236,15 @@ def _set_axis_lbl(self, fun, units, plotlbl):
def _plot(self, logx=False, logy=False, imag=False):
fig = self._init_plot(imag)
ls,ss = self.get_plot_info(logx, logy, imag)
if self.cycle_dashes:
# At least as many dashes for number of lines
self.dashes = self.dashes * len(ls)
if self.dashes is not None:
for i in range(len(self.dashes)):
if i >= len(ls):
break
if self.dashes[i] is not None:
ls[i].set_dashes(self.dashes[i])
if ss is not None and len(self.colour_cycle)>1:
plt.legend(ls, ss)
self._set_axis_lbl(plt.xlabel, self.x_units, self.x_plotlbl)
Expand All @@ -240,10 +257,11 @@ def get_plot_info(self, logx=False, logy=False, imag=False):

def _init_plot(self, imag):
fig = plt.figure(facecolor="white")
if not imag:
fig.suptitle(self.chart_title)
else:
fig.suptitle(self.chart_title + " imag")
if self.chart_title is not None:
if not imag:
fig.suptitle(self.chart_title)
else:
fig.suptitle(self.chart_title + " imag")
if self.xsize is not None and self.ysize is not None:
fig.set_size_inches(self.xsize, self.ysize, forward=True)
plt.gca().set_prop_cycle(cycler('color', self.colour_cycle))
Expand Down
2 changes: 1 addition & 1 deletion matfuncutil/release.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1"
__version__ = "1.1.0"
17 changes: 15 additions & 2 deletions matfuncutil/tests/demo_singleplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@

a = dum_mats.row_offset_col_gain_zeroimag()
a.set_chart_title("Test title a")
a.plot()
a.set_chart_parameters(dashes=[None,[10,10],[50,50]])
a.plot(save_path=basedir+os.sep+"charts\\chart.png", add_axis_lmts=True)

a.set_chart_parameters(dashes=[[10,10]])
a.plot(add_axis_lmts=True)

a.set_chart_parameters(dashes=[[10,10]], cycle_dashes=True)
a.plot(add_axis_lmts=True)

b = a.create_reduced_dim(0)
b.set_chart_title("Test title b")
b.plot(logx=True, logy=True)
b.set_chart_parameters(xsize=4., ysize=4., dpi=2400)
b.plot(logx=True, logy=True, save_path=basedir+os.sep+"charts\\chart2.png")

c = b.create_reduced_dim(1)
c.set_chart_title(None)
c.set_chart_parameters(leg_prefix="Test", xsize=10, ysize=10)
c.plot(imag=True)
c.plot(imag=True, save_path=basedir+os.sep+"charts\\chart3.pdf")

d = a.trace()
d.plot()
Expand All @@ -32,4 +42,7 @@
dSin.plot()

dSin2 = dSin.create_reduced_length(-math.pi, math.pi, 20)
dSin2.plot()

dSin2.set_chart_parameters(dashes=[[50,50]])
dSin2.plot()

0 comments on commit df5456c

Please sign in to comment.