Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Plots issue
#1
I'm plotting the few figures however, unable to plot below is my code. Kindly guide me.
#!/usr/bin/env python3


import matplotlib.pyplot as plt
import matplotlib.gridspec as gspec
import numpy as np
import seaborn as sns

def plot_res(charge_arr, status_arr, P_arr, power_vec, time_vec, max_charge,fignum=None):
    

#    # status pallete (-1...6)
    status_pal = ["#909090",   #gray   = -1 -always noted
                  "#000000",   #black  =  0 - only Noted 
                  "#ffffff",   #white  =  1 - Cells
                  "#ffbb00",   #orange =  2 - available
                  "#ff0000",   #red    =  3 - info
                  "#00FF00",   #green  =  4 - starting
                  "#ff00ff",   #purple  = 5 - Not happened
                  "#0000ff"]   #blue   =  6 - newly

    # status pallete (-1...6)
    status_pal = sns.cubehelix_palette(8, rot=-1, dark=0.1, light=1,
                                       reverse=False)

#     new one
    status_pal = ["#cccccc",  # gray   = -1 - always noted
                  "#0a0a0a",  # dark blue  =  0 - only Noted
                  "#ffcd1d",  # yellow =  1 - Queued
                  "#27de17",  # l. green=  2 - Not ready 
                  "#ff3917",  # red    =  3 - Forced
                  "#182050",  # blue =  4 - Ready
                  "#ff00ff",  # purple  = 5 - In Use, discharging
                  "#0000ff"]  # blue   =  6 - In Use, charging
    # same palette, a bit more faded
    status_pal = ["#cccccc",  # gray   = -1 - N/A
                  "#0a0a0a",  # dark blue  =  0 - An idea
                  "#ffd74a",  # yellow =  1 - not new
                  "#52e445",  # l. green=  2 - Charging (available)
                  "#ff6145",  # red    =  3 - Charginf(Forced)
                  "#464c73",  # blue  =  4 - Ready
                  "#ff00ff",  # purple  = 5 - northern, 
                  "#0000ff"]  # blue   =  6 - In line, 
    # same palette, a bit less faded
    status_pal = ["#cccccc",  # gray   = -1 - N/A
                  "#000000",  # black  =  0 - Not in use
                  "#ffd234",  # yellow =  1 - Queued
                  "#2f3661",  # d. blue=  2 - Computer
                  "#ff4d2e",  # red    =  3 - wine roots
                  "#347436",  # green  =  4 - Ready
                  "#ff00ff",  # purple  = 5 - In Use, 
                  "#0000ff"]  # blue   =  6 - yellow priest


    # charge percentage palette, extremes modified to highlight min and max
    charge_pal = sns.cubehelix_palette(10*max_charge, reverse=True)
#    charge_pal[0] = [0.8, .8, .8]
#    charge_pal[1] = [0, 0, 0]
#    charge_pal[-1] = [0, .7, 0]
    charge_pal = sns.cubehelix_palette(3*max_charge, reverse=True, rot=0,
                                       hue=0, dark=0, light=.8)
#    charge_pal = (np.linspace(0, 1, 101)*np.ones((3, 1))).T
    charge_pal[-1] = [0.20392157, 0.45490196, 0.21176471]
    charge_pal[0] = [.8, .8, .8]

    step = int(np.round(1/np.median(np.diff(time_vec))))
    xticks = np.arange(len(time_vec) + 1)[::step]
    xlabels = np.remainder(time_vec, 24)[::step].astype(int)
    plt.show(sns)
    
    if fignum is None:
        fignum = plt.figure(figsize=(16, 6)).number
    else:
        plt.figure(fignum)
        plt.clf()

    fig = plt.figure(fignum, figsize=(50, 20))
    ax = fig.subplots(3, 2, sharex='col',#False,#'col',
#                      gridspec_kw={'width_ratios': [1, 1]})
                      gridspec_kw={'width_ratios': [20, 1]})
    ax = np.ravel(ax)

    # Charge values
    ax[0].set_title('cells, %')
    #charge_p = [c/c.max() if c.sum() else np.zeros(len(c)) for c in charge_arr]
    charge_p = charge_arr
    sns.heatmap(np.array(charge_p), vmin=0, vmax=max_charge, cmap=charge_pal,

                xticklabels=np.remainder(time_vec, 24), ax=ax[0],
                cbar_ax=ax[1])
    # set colorbar text
    ax[0].set_xticks(xticks)
    ax[0].set_xticklabels(xlabels)

    # Status
    ax[2].set_title('Status')
    cbar_kws = { 'ticks': [ np.arange(-.5, 7.5, 1)]}
                 #'values': [[ 'N/A', '0', '1', '2', '3', '4', '5', '6']] }

    sns.heatmap(status_arr, vmin=-1, vmax=7, cmap=status_pal,

                xticklabels=np.remainder(time_vec, 24), ax=ax[2],
                cbar_ax=ax[3], cbar_kws=cbar_kws)
    ax[2].set_xticks(xticks)
    ax[2].set_xticklabels(xlabels)
    plt.show()
#    # Power draw
    ax[4].set_title('Magnetic flux intensity')
    ax[4].plot(charge_arr[charge_arr.sum(1) > 0].T, color='k', alpha=.3)
    ax[4].set_title('Total Loss gain')
#    ax[4].plot(P_arr.sum(0))
    xstep = np.arange(len(time_vec) + 1)#((time_vec, time_vec[-1:] + step))
    ystep = P_arr.sum(0)
    ystep = np.concatenate((ystep, ystep[-1:]))
    ax[4].step(xstep, ystep, where='post')
    ax[4].plot(tissuevector, 'k-.', alpha=.5)
    ax[4].set_xticks(xticks)
    ax[4].set_xticklabels(xlabels)
    plt.show()
    ax[4].grid()
    ax[4].set_ylim(0)
    ax[4].set_xlim(min(xticks), max(xticks))
    fig.tight_layout()
    return fig
Quote
#2
Think Think Think Think NO response
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Add space between plots AdWill97 0 176 May-15-2019, 02:04 PM
Last Post: AdWill97
  How to change the resolution of an image and save multiple plots. pianistseb 1 375 Dec-11-2018, 07:45 PM
Last Post: micseydel
  2D to 3D plots ekq378 0 433 Nov-14-2018, 06:13 PM
Last Post: ekq378
  Three-dimensional Contour Plots minifizikus 1 791 Sep-13-2018, 10:56 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)