Add functions to assign tickmarks
This commit is contained in:
parent
8fafdefc71
commit
8d1bee56be
1 changed files with 64 additions and 6 deletions
|
|
@ -599,11 +599,6 @@ def prettify_labels(label):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generate_colours(options):
|
def generate_colours(options):
|
||||||
|
|
||||||
default_options = {
|
default_options = {
|
||||||
|
|
@ -686,4 +681,67 @@ def generate_markers(options):
|
||||||
else:
|
else:
|
||||||
markers = [options['markers'][0], options['markers'][1]]
|
markers = [options['markers'][0], options['markers'][1]]
|
||||||
|
|
||||||
return markers
|
return markers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_tickmarks(df: pd.DataFrame, ticks: list, value: str, exclude=None):
|
||||||
|
|
||||||
|
|
||||||
|
min_val = df[value].min()
|
||||||
|
max_val = df[value].max()
|
||||||
|
|
||||||
|
|
||||||
|
# Get major ticks
|
||||||
|
major_ticks = [np.round((min_val + ticks[0]*i),2) for i in range(int(np.floor((max_val-min_val)/ticks[0]))+1)]
|
||||||
|
major_ticks.append(np.round(max_val, 2))
|
||||||
|
|
||||||
|
major_ticks = aux.get_unique(major_ticks)
|
||||||
|
|
||||||
|
major_ticklabels = [i*ticks[0] for i in range(len(major_ticks)-1)]
|
||||||
|
major_ticklabels.append(np.round((max_val-min_val),1))
|
||||||
|
|
||||||
|
if exclude:
|
||||||
|
for i, tick in enumerate(major_ticklabels):
|
||||||
|
if tick in exclude:
|
||||||
|
del major_ticks[i]
|
||||||
|
del major_ticklabels[i]
|
||||||
|
|
||||||
|
|
||||||
|
# Get minor ticks
|
||||||
|
minor_ticks = [np.round((min_val + ticks[1]*i),2) for i in range(int(np.floor((max_val-min_val)/ticks[1]))+1) if np.round((min_val + ticks[1]*i),2) not in major_ticks]
|
||||||
|
minor_ticklabels = [np.round(tick - min_val, 2) for tick in minor_ticks]
|
||||||
|
|
||||||
|
return major_ticks, major_ticklabels, minor_ticks, minor_ticklabels
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def assign_tickmarks(dfs: list, options, fig, ax, exclude=None):
|
||||||
|
|
||||||
|
major_ticks, major_ticklabels, minor_ticks = [], [], []
|
||||||
|
|
||||||
|
if not exclude:
|
||||||
|
exclude = [[None, None] for i in range(len(options['which_cycles']))]
|
||||||
|
|
||||||
|
for i, cycle in enumerate(options['which_cycles']):
|
||||||
|
#Get ticks from charge cycle
|
||||||
|
major_tick, major_ticklabel, minor_tick, minor_ticklabel = ec.plot.get_tickmarks(dfs[cycle][0], ticks=options['x_tick_locators'], value=options['x_vals'], exclude=exclude[i][0])
|
||||||
|
major_ticks += major_tick
|
||||||
|
major_ticklabels += major_ticklabel
|
||||||
|
minor_ticks += minor_tick
|
||||||
|
|
||||||
|
# Get ticks from discharge cycle
|
||||||
|
major_tick, major_ticklabel, minor_tick, minor_ticklabel = ec.plot.get_tickmarks(dfs[cycle][1], ticks=[1, 0.25], value='ions', exclude=exclude[i][1])
|
||||||
|
major_ticks += major_tick
|
||||||
|
major_ticklabels += major_ticklabel
|
||||||
|
minor_ticks += minor_tick
|
||||||
|
|
||||||
|
|
||||||
|
ax.set_xticks(major_ticks, minor=False)
|
||||||
|
ax.set_xticklabels(major_ticklabels)
|
||||||
|
ax.set_xticks(minor_ticks, minor=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return fig, ax
|
||||||
Loading…
Add table
Add a link
Reference in a new issue