Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_ts is visually wrong #694

Open
aluthfian opened this issue Jun 18, 2023 · 0 comments
Open

plot_ts is visually wrong #694

aluthfian opened this issue Jun 18, 2023 · 0 comments

Comments

@aluthfian
Copy link

aluthfian commented Jun 18, 2023

What command was run:
I am running plot_ts, and it produced an inaccurate timescale display (look at the boundaries vs. age)

fig=plt.figure(figsize=(9,12), dpi=60) # make the figure
ax=fig.add_subplot(121) # make the first of three subplots
pmagplotlib.plot_ts(ax,0.1,1.0,timescale='gts12')

What happened:
Changing agemin and agemax parameters in plot_ts produces wrong magnetostratigraphic cycle boundaries.

What I expected to happen:
A correct magnetostratigraphic boundary regardless of agemin and agemax parameters in plot_ts.

Data file(s):
Not applicable

PmagPy version:
pmagpy-4.2.109, plus jupyter lab 3.5.3 and matplotlib 3.6.2

Possible workaround

  1. Use sharey in the plot_ts
  2. Use boolean to filter values within agemin and agemax limits.
  3. Separate the text creation and line creation into a series of ifs (probably inefficient?)
  4. Use a slightly modified timescale-chron format: [[chron_name_0, up_bound_0], [chron_name_1, up_bound_1], ..., [chron_name_N, up_bound_N], [chron_name_N, lower_bound_N]]. The gts22 timescale already adopted this.

Example timescale-chron formatting in pmag.py file, section get_ts
This is taken from ICS 2022 Magnetostratigraphic chart, ignoring the small excursions.

TS = [0, 0.773, 0.990, 1.071, 1.187, 1.208, 1.780, 1.925, 2.116, 2.137, 2.595, 2.900] #timescale
Labels = [['Brunhes', 0.000], ['Matuyama', 0.773], ['Jaramillo', 0.990], ['Matuyama', 1.071], ['Cobb Mtn.', 1.187], ['Matuyama', 1.208], ['Olduvai', 1.780], ['Matuyama', 1.925], ['Reunion', 2.116], ['Matuyama', 2.137], ['Gauss', 2.595], ['Gauss', 2.900]] #chrons

Proposed plot_ts for Line 3669 in pmagplotlib.py
Edited Line

def plot_ts(ax, agemin, agemax, step=1.0, timescale='gts12', ylabel="Age (Ma)"):
    """
    Make a time scale plot between specified ages.

    Parameters:
    ------------
    ax : figure object
    agemin : Minimum age for timescale in Ma
    agemax : Maximum age for timescale in Ma
    step : Y tick label spacing in Ma
    timescale : Time Scale [ default is Gradstein et al., (2012), gts12 ], other options are ck95, gts04, ics22, or gts12
    ylabel : if set, plot as ylabel
    """
    ax.set_title(timescale.upper())
    column_bnd = 0.8
    ax.axis([-.25, 1.5, agemax, agemin])
    ax.axes.get_xaxis().set_visible(False)
    # get dates and chron names for timescale
    TS, Chrons = pmag.get_ts(timescale)
    X, Y, Y2 = [0, column_bnd], [], []
    cnt = 0
    if agemin < TS[1]:  # in the Brunhes
        Y = [agemin, agemin]  # minimum age
        Y1 = [TS[1], TS[1]]  # age of the B/M boundary
        ax.fill_between(X, Y, Y1, facecolor='black')  # color in Brunhes, black
    for d in TS[1:]:
        pol = cnt % 2
        cnt += 1
        if d <= agemax and d >= agemin:
            ind = TS.index(d)
            Y = [TS[ind], TS[ind]]
            Y1 = [TS[ind+1], TS[ind+1]]
            if pol:
                # fill in every other time
                ax.fill_between(X, Y, Y1, facecolor='black')
    ax.plot([0, column_bnd, column_bnd, 0, 0], [agemin, agemin, agemax, agemax, agemin], 'k-')
    max_y_tick = agemin + np.floor((agemax-agemin)/step)*step
    total_step = np.rint(((max_y_tick-agemin)/step)+1).astype(int)
    plt.yticks(np.linspace(agemin, max_y_tick, total_step))
    ax.set_ylim(agemin, agemax)
    if ylabel != "":
        ax.set_ylabel(ylabel)
    ax2 = ax.twinx()
    ax2.sharey(ax)
    ax2.axis('off')
    """
    NEW STUFF
    """
    within_range = [(age[1]>=agemin)&(age[1]<=agemax) for age in Chrons]
    ticker_num = 0
    for k in range(len(Chrons)-1):
        c = Chrons[k]
        cnext = Chrons[k+1]
        d_plot = cnext[1]-(cnext[1]-c[1])
        if (d_plot >= agemin) and (d_plot < agemax):
            # make the Chron boundary tick
            ax2.plot([column_bnd, 1.5], [c[1], c[1]], 'k-')
        if ((within_range[k]==False)&(within_range[k+1]==True))&(ticker_num == 0):
            d_txt = agemin + 0.5*np.abs(cnext[1]-agemin)
            ax2.text(column_bnd+0.05, d_txt, c[0], verticalalignment='center')
            ticker_num += 1
        elif ((within_range[k]==True)&(within_range[k+1]==False))&(ticker_num == 1):
            d_txt = agemax - 0.5*np.abs(agemax-c[1])
            ax2.text(column_bnd+0.05, d_txt, c[0], verticalalignment='center')
            ticker_num += 1
        elif (within_range[k]==True)&(within_range[k+1]==True):
            d_txt = cnext[1]-(cnext[1]-c[1])/2.5
            ax2.text(column_bnd+0.05, d_txt, c[0], verticalalignment='center')
    ax2.axis([-.25, 1.5, agemax, agemin])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant