Пример #1
0
 def showBarChart(title, xLabel, yLabel, labels, dataList, color, isBarH):
     plt.title(title)
     plt.xlabel(xLabel)
     plt.yLabel(yLabel)
     if isBarH:
         plt.barh(labels, dataList, color=color)
     else:
         plt.bar(labels, dataList, color=color)
     plt.show()
Пример #2
0
def plot_hist_comp(data, data2, dataLabels, title='', xLabel=''):
    """!
    @ingroup OptiPlot
    Histograms and plots the comparison of two sets of function evaluation data.

    @param data: \e list \n
        Contains the number of function evals for each optimization run. \n
    @param data2: \e list \n
        Contains the number of function evals for each optimization run for a
        second set of runs. \n
    @param dataLabels: \e list \n
        Contains the legend label names for each data set. \n

    @param title: \e string \n
        Title for plot. \n
    @param xLabel: \e string \n
        Label for independent variable. \n
    """

    # Allow use of Tex sybols and set formats
    plt.rc('text', usetex=True)
    plt.rcParams['savefig.dpi'] = 900

    # Establish labels for each data set and title for the plot
    if xLabel == '':
        xLabel = ('\\textbf{# Function Evals}')
    yLabel = ('\\textbf{Probability}')
    if title == '':
        title = "Histogram of Function Evaluations for Optimization"

    # Plot Histogram
    num = len(data)
    w = np.ones_like(data)/float(num)

    maxVal = max([max(data), max(data2)])
    bins = np.arange(0, maxVal, ceil(maxVal/100))

    plt.hist(data, bins=bins, weights=w, facecolor='black',
             histtype='stepfilled', alpha=1.0, label=dataLabels[0])
    plt.hist(data2, bins=bins, weights=w, facecolor='grey',
             histtype='stepfilled', alpha=0.85, label=dataLabels[1])

    # Plot Labels
    plt.xLabel('\\textbf{%s}' %xLabel, fontsize=15, y=-01.04)
    plt.yLabel('\\textbf{%s}' %yLabel, fontsize=15, x=-0.04)
    plt.title('\\textbf{%s}' %title, fontsize=17, y=1.04)
    plt.yticks(fontsize=14)
    plt.xticks(fontsize=14)

    # Tweak spacing to prevent clipping of yLabel
    plt.subplots_adjust(left=0.15)

    # Add legend
    plt.legend(borderaxespad=0.75, loc=1, fontsize=14, handlelength=5,
               borderpad=0.5, labelspacing=0.75, fancybox=True, framealpha=0.5)
    plt.show()
Пример #3
0
def plot_tlf(alpha=1.5, gamma=1., numSamp=1E7, cutPoint=10.):
    """!
    @ingroup OptiPlot
    Plots a comparison of the TLF to the Levy distribution.

    @param alpha: \e float \n
        Levy exponent - defines the index of the distribution and controls
        scale properties of the stochastic process.
    @param gamma: \e float \n
        Gamma - Scale unit of process for Levy flights. \n
    @param numSamp: \e integer \n
        Number of Levy flights to sample. \n
    @param cutPoint: \e float \n
        Point at which to cut sampled Levy values and resample. \n
    """

    # Initialize variables
    l = []  #List to store Levy distribution values
    bins = np.array(range(0, int(cutPoint + 1), 1)) / cutPoint

    # Calculate the Levy distribution
    for i in range(0, len(bins)):
        l.append(1/pi*integrate.quad(lambda x: exp(-gamma*x**(alpha)) \
                                     *cos(x*bins[i]*cutPoint),
                                     0, float("inf"), epsabs=0, epsrel=1.e-5,
                                     limit=150)[0]*2)

    # Draw numSamp samples from the Levy distribution
    levySamp = abs(levy(1, numSamp) / cutPoint).reshape(numSamp)

    # Resample values above the range (0,1)
    for i in range(len(levySamp)):
        while levySamp[i] > 1:
            levySamp[i] = abs(levySamp(1, 1) / cutPoint).reshape(1)

    #Plot the TLF and Levy distribution on the interval (0,1)
    w = np.ones_like(levySamp) / float(
        numSamp)  #Weights to normalize histogram
    plt.rc('text', usetex=True)
    ax = plt.subplot(111)
    ax.hist(levy, bins=bins, facecolor='grey', weights=w)
    ax.plot(bins, l, color='k', linewidth=3.0)
    ax.set_yscale("log")
    plt.xLabel('\\textbf{z}', fontsize=15, y=-0.04)
    plt.yLabel('\\textbf{P(z)}', fontsize=15, x=-0.04)
    plt.title('\\textbf{Comparison of TLF and Levy Function}', fontsize=17)

    plt.yticks(fontsize=14)
    plt.xticks(fontsize=14)

    plt.show()

# In[ ]:


td = data[data.TotalDeath == 'Total Deaths']


# In[ ]:


td


# In[ ]:


plt.plot(tc.Dates_epicrv, tc.Dates_epicrv / 10**6)
plt.plot(td.Dates_epicrv, td.Dates_epicrv / 10**6)
plt.xLabel('time')
plt.yLabel('Those infected')
plt.legend(['Total Cases', 'Total Deaths'])
plt.show()


# In[ ]: