|
- """
- =======================================
- A simple plot with a custom dashed line
- =======================================
-
- A Line object's ``set_dashes`` method allows you to specify dashes with
- a series of on/off lengths (in points).
- """
- import numpy as np
- import matplotlib.pyplot as plt
- import seaborn as sns
- import pandas as pd
-
- plt.rc('font',family='Times New Roman')
-
-
- def y_1(x):
- y = np.zeros(x.shape)
- max_x = np.max(x)
- max_x += 1
- y[np.where(x <= (max_x / 3.))] = 1. / (max_x-1)
- y[np.where(x >= (2 * max_x / 3.))] = -1. / (max_x-1)
- return y
-
-
- def y_2(x, beta=1.5, gama=0.4):
- _x = x
- _x = (_x - np.mean(_x)) / np.max(_x) * beta
- _w = np.flip(np.clip(gama * np.log((1 + _x) / (1 - _x)), a_min=-1, a_max=1))
- return _w
-
-
- fontsize = 15
- x = np.linspace(1, 7, 500)
- x = np.array(range(1,8,1))
- dashes = [10, 5, 100, 5] # 10 points on, 5 off, 100 on, 5 off
-
- fig, ax = plt.subplots()
-
-
- line1, = ax.plot(x, y_1(x), 'ro-',
- label='selective function')
-
- line2, = ax.plot(x, y_2(x, beta=1.5, gama=0.4),'gD-',
- label='log function ' + r"$\gamma=0.4$")
- line3, = ax.plot(x, y_2(x, beta=1.5, gama=0.2),'b^-',
- label='log function ' + r"$\gamma=0.2$")
- ax.spines['bottom'].set_linewidth(2)
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- for tick in ax.yaxis.get_major_ticks():
- tick.label.set_fontsize(15)
- for tick in ax.xaxis.get_major_ticks():
- tick.label.set_fontsize(15)
-
- ax.legend(loc=3, fontsize=17)
- ax.set_yscale('linear')
- plt.axis('tight')
- ax.set_xlabel(r"$rk(c_i)$", fontsize=17)
- ax.set_ylabel(r"$W_{\theta_t}^f$ ", fontsize=17)
- ax.xaxis.set_label_coords(0.5, -0.08)
- ax.yaxis.set_label_coords(-0.08, 0.5)
- # ax.set_yticks(np.arange(*graph_ranges[i]))
- ax.grid(linestyle='-.', linewidth=1)
- plt.savefig('k_line_v3.pdf')
- plt.show()
|