小编Sco*_* B.的帖子

在matplotlib中将垂直线添加到Date格式化的时间序列

我正在尝试将红色垂直线添加到时间序列图中,其中x轴格式为%Y-%m-%d.我想添加该行的日期是2013-05-14.只需在"plt.show()"之前添加该行:

plt.axvline(x=2013-05-14)
Run Code Online (Sandbox Code Playgroud)

要么:

plt.axvline(x='2013-05-14')
Run Code Online (Sandbox Code Playgroud)

返回错误:

RuntimeError: RRuleLocator estimated to generate 23972 ticks from 0044-05-12 23:59:59.999990+00:00 to 2013-06-07 00:00:00.000010+00:00: exceeds Locator.MAXTICKS * 2 (2000) 
Run Code Online (Sandbox Code Playgroud)

这是函数,它运行良好,因为它是:

 def time_series(self):
    fig = plt.figure(figsize=(20, 20), frameon = False)
    ax1 = fig.add_subplot(3, 1, 1)


    d_dates, d_flux_n2o, d_sem_n2o = np.loadtxt('%stime_series/dynamic.csv' %self.dir['r_directory'],  delimiter = ',', unpack=True, converters={0: mdates.strpdate2num('%Y-%m-%d')})

    ax1.set_xlabel('Date')
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
    ax1.xaxis.set_major_locator(mdates.MonthLocator())
    ax1.xaxis.set_minor_locator(mdates.DayLocator())
    plt.gcf().autofmt_xdate()

    ax1.errorbar(d_dates, d_flux_n2o, yerr=d_sem_n2o, fmt="y-", linewidth=1.5, label = 'Biodynamic')
    ax1.legend(loc = 0)

    plt.show()
Run Code Online (Sandbox Code Playgroud)

time-series matplotlib date-formatting

4
推荐指数
1
解决办法
4210
查看次数

在 R 中同时将“1”替换为“0”和“0”替换为“1”

我在 R 中有一个字符向量,例如:

> row
"1/1" "0/0" "0/0" "1/1" "0/1" "0/0" "1/0" 
Run Code Online (Sandbox Code Playgroud)

我想交换“1”和“0”字符以返回一个向量:

> row2
"0/0" "1/1" "1/1" "0/0" "1/0" "1/1" "0/1"
Run Code Online (Sandbox Code Playgroud)

我觉得这是一项简单的任务,但我感到困惑,因为我假设多次调用gsub例如会在第二次调用时逆转转换过程。

关于基于 R 的解决方案的任何想法?谢谢!

regex string replace r gsub

2
推荐指数
1
解决办法
42
查看次数

标签 统计

date-formatting ×1

gsub ×1

matplotlib ×1

r ×1

regex ×1

replace ×1

string ×1

time-series ×1