Aug-06-2019, 07:10 AM
I'm plotting the few figures however, unable to plot below is my code. Kindly guide me.
#!/usr/bin/env python3
#!/usr/bin/env python3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
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 |