<jupyter_start><jupyter_text>Bar Plot<jupyter_code># Use go.Bar to plot Bar charts in Plotly
x = np.arange(1,10)
y = np.arange(20,110,10)
data = go.Bar(
             x= x,
             y= y,
             )

layout = go.Layout(
                  title = 'Simple Bar Chart'
                  )


fig = go.Figure(data=data,layout=layout)
fig.show()
# Use go.Bar to plot Bar charts in Plotly
x1 = [1,2,3,3,3,4,5]
y1 = [10,20,30,40,50,60,65]


data = go.Bar(
             x= x1,
             y= y1,
             )

layout = go.Layout(
                  title = 'Simple Bar Chart'
                  )

fig = go.Figure(data=data,layout=layout)
fig.show()
#Changing color of Bar plot
x = np.arange(1,10)
y = np.arange(20,130,10)
data = go.Bar(
             x= x,
             y= y,
             marker={'color' : '#FFA726'} # changing color of bar plot
             )

layout = go.Layout(
                  title = 'Simple Bar Chart',
                  width=970,
                  height=650
                  )


fig = go.Figure(data=data,layout=layout)
fig.show()
# Changing width of Bar Plot
x = np.arange(1,10)
y = np.arange(20,130,10)
wid = [0.2,]*9
data = go.Bar(
             x= x,
             y= y,
             marker={'color' : '#FFA726'}, # Changing color of bars 
             width=wid # Changing width of Bars
             )

layout = go.Layout(
                  title = 'Simple Bar Chart',
                  width=970,
                  height=650
                  )


fig = go.Figure(data=data,layout=layout)
fig.show()
x = np.arange(1,10)
y = np.arange(20,130,10)
data = go.Bar(
             x= x,
             y= y,
             marker_color= '#FFA726', # Changing color of Bars
             marker_line_color = '#A04000', # Changing color of border
             marker_line_width = 2, # Changing width of border
             opacity=0.7 # Changing opacity of Bars
             )

layout = go.Layout(
                  title = 'Simple Bar Chart',
                  width=970,
                  height=650
                  )


fig = go.Figure(data=data,layout=layout)
fig.show()
# Simple Horizontal Bar Plot (Using orientation='h')
x = np.arange(1,10)
y = np.arange(20,130,10)
data = go.Bar(
             x= y,
             y= x,
             marker={'color' : '#FFA726'},
             orientation='h'
             )

layout = go.Layout(
                  title = 'Simple Bar Chart',
                  width=970,
                  height=650
                  )


fig = go.Figure(data=data,layout=layout)
fig.show()
Assignee = ['Asif', 'Basit', 'John', 'Charles','Vignesh', 'Arun', 'Ashish', 'Varun']
Tickets_Closed = np.array([52,42,60,35,48,45,28,54])
per = (Tickets_Closed/sum(Tickets_Closed))*100
per = np.round(per, decimals=2)

#Create dataframe
helpdesk = pd.DataFrame({'Assignee' : Assignee, 'Tickets Closed' :Tickets_Closed , 'Percentage': per})
helpdesk = helpdesk.sort_values(by='Percentage')

#Initialize the figure
fig = go.Figure()

#Plot Closure percentage using Horizontal Bar plot
fig.add_trace(go.Bar(
                     x=helpdesk.Percentage,
                     y=helpdesk.Assignee,
                     orientation='h',
                     marker=dict(
                                  color='rgba(70, 171, 100, 0.6)',
                                  line=dict(color='rgba(70, 171, 100, 1.0)',width=1),
                                 ),
                     )
             )

#Update layout
fig.update_layout(
                   title=dict(text = "Ticket Closure Summary",x=0.46,y=0.95,font_size=20),
                   yaxis=dict(
                              showticklabels=True,
                              ),

                   xaxis=dict(
                                showticklabels=False,
                                domain=[0, 0.6],
                             ),
                   margin=dict(l=300, r=20, t=70, b=70),
                   paper_bgcolor='rgb(248, 248, 255)',
                   plot_bgcolor='rgb(248, 248, 255)',
                  )



annotations = [] #Initialize anotation object


# Labels
for perc, asg in zip(helpdesk.Percentage, helpdesk.Assignee):
    
    # Displaying label bar percentage
    annotations.append(dict(xref='x', 
                            yref='y',
                            y=asg, 
                            x=perc + 2,
                            text=str(perc) + '%',
                            font=dict(family='Arial', size=12,color='#004D40'),
                            showarrow=False))
   # Displaying Footer
    annotations.append(dict(xref='paper', 
                            yref='paper',
                            x=1, 
                            y=-0.17,
                            text='Help Desk ' +'Closure Statistics, ' +'Year 2020',
                            font=dict(family='Arial', size=11, color='#9E9E9E'),
                            showarrow=False
                           )
                       )

fig.update_layout(annotations=annotations)

fig.show()
x1= [1,3,5,7] 
x2=[2,4,6,8]
y1 = [7,7,7,7]
y2= [17,18,29,40]

trace0 = go.Bar(
             x= x1,
             y= y1,
             marker= dict (color ='#FFA726' )
             
             )

trace1 = go.Bar(
             x= x2,
             y= y2,
             marker={'color' : '#94E413'}
             )


data = [trace0,trace1]
fig = go.Figure(data=data)
fig.show()<jupyter_output><empty_output><jupyter_text>Stacked Vertical Bar<jupyter_code>x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] 
y1 = [17,18,29,33,38,39,42]
y2 = [20,21,22,23,21,28,25]
y3 = [5,13,11,12,13,11,16]
trace0 = go.Bar(
             x= x,
             y= y1,
             marker= dict (color ='#FF6F00' ),
             name = 'Open Tickets'
             
             )

trace1 = go.Bar(
             x= x,
             y= y2,
             marker={'color' : '#FFB300'},
              name = 'Closed Tickets'
              )    

trace2 = go.Bar(
             x= x,
             y= y3,
             marker={'color' : '#F7DC6F'},
              name = 'Cancelled Tickets'
              )  
    
layout = go.Layout(
                   title= 'Open Tickets by Status' , 
                   barmode = 'stack',
                   width=900,
                   height=800
                  )


data = [trace0,trace1,trace2]
fig = go.Figure(data=data, layout=layout)
fig.show()
#Displaying values in bar plot using "text" and "textposition" parameter
x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] 
y1 = [17,18,29,33,38,39,42]
y2 = [20,21,22,23,21,28,25]
y3 = [5,13,11,12,13,11,16]
trace0 = go.Bar(
             x= x,
             y= y1,
             marker= dict (color ='#FF6F00' ),
             name = 'Open Tickets',
             text=y1,
             textposition='auto'             
             )

trace1 = go.Bar(
             x= x,
             y= y2,
             marker={'color' : '#FFB300'},
             name = 'Closed Tickets',
             text=y2,
             textposition='auto'     
              )    

trace2 = go.Bar(
             x= x,
             y= y3,
             marker={'color' : '#F7DC6F'},
             name = 'Cancelled Tickets',
             text=y3,
             textposition='auto'     
              )  
    
layout = go.Layout(
                   title= 'Open Tickets by Status' , 
                   barmode = 'stack',
                   width=900,
                   height=800
                  )


data = [trace0,trace1,trace2]
fig = go.Figure(data=data, layout=layout)
fig.show()<jupyter_output><empty_output><jupyter_text>Stacked Horizontal Bar<jupyter_code>x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] 
y1 = [17,18,29,33,38,39,42]
y2 = [20,21,22,23,21,28,25]
y3 = [5,13,11,12,13,11,16]

trace0 = go.Bar(
             x= y1,
             y= x,
             marker= dict (color ='#FF6F00'),
             name = 'Open Tickets',
             orientation='h',
             text=y1,
             textposition='auto'           
             )

trace1 = go.Bar(
             x= y2,
             y= x,
             marker={'color' : '#FFB300'},
             name = 'Closed Tickets',
             orientation='h',
             text=y2,
             textposition='auto'  
              )    


trace2 = go.Bar(
             x= y3,
             y= x,
             marker={'color' : '#F7DC6F'},
             name = 'Cancelled Tickets',
             orientation='h',
             text=y3,
             textposition='auto'  
              )  
    
layout = go.Layout(
                   title= 'Open Tickets by Status' , 
                   barmode = 'stack',
                   width=990,
                   height=550
                  )

data = [trace0,trace1,trace2]
fig = go.Figure(data=data, layout=layout)

fig.show()
x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] 
y1 = [17,18,29,33,38,39,42]
y2 = [20,21,22,23,21,28,25]
y3 = [5,13,11,12,13,11,16]

trace0 = go.Bar(
             x= y1,
             y= x,
             marker= dict (color ='#FF9800',line=dict(color='#F4511E',width=2)),
             name = 'Open Tickets',
             orientation='h',
             text=y1,
             textposition='auto',
             opacity=0.8,
             )

trace1 = go.Bar(
             x= y2,
             y= x,
             marker= dict (color ='#7CB342',line=dict(color='#2E7D32', width=2)),
             name = 'Closed Tickets',
             orientation='h',
             text=y2,
             textposition='auto',
             opacity=0.8,   
              )    


trace2 = go.Bar(
             x= y3,
             y= x,
             marker= dict (color ='#1E88E5',line=dict(color='#3F51B5', width=2)),
             name = 'Cancelled Tickets',
             orientation='h',
             text=y3,
             textposition='auto',
             opacity=0.7,   
              )  
    
layout = go.Layout(
                   title= 'Open Tickets by Status' , 
                   barmode = 'stack',
                   width=990,
                   height=600
                  )

data = [trace0,trace1,trace2]
fig = go.Figure(data=data, layout=layout)

fig.show()<jupyter_output><empty_output><jupyter_text>Grouped Bar Chart<jupyter_code>x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] 
y1 = [17,18,29,33,38,39,42]
y2 = [20,21,22,23,21,28,25]
y3 = [5,13,11,12,13,11,16]
trace0 = go.Bar(
             x= x,
             y= y1,
             marker= dict (color ='#FF6F00' ),
             name = 'Open Tickets',
             )

trace1 = go.Bar(
             x= x,
             y= y2,
             marker={'color' : '#FFB300'},
              name = 'Closed Tickets'
              )    

trace2 = go.Bar(
             x= x,
             y= y3,
             marker={'color' : '#F7DC6F'},
              name = 'Cancelled Tickets'
              )  
    
layout = go.Layout(
                   title= 'Open Tickets by Status' , 
                   width=980,
                   height=800
                  )


data = [trace0,trace1,trace2]
fig = go.Figure(data=data, layout=layout)

fig.show()
# Grouped Bar Chart with values displayed outside the bar (Using  textposition='outside')
x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] 
y1 = [17,18,29,33,38,39,42]
y2 = [20,21,22,23,21,28,25]
y3 = [5,13,11,12,13,11,16]
trace0 = go.Bar(
             x= x,
             y= y1,
             marker= dict (color ='#FF6F00' ),
             name = 'Open Tickets',
             text=y1,
             textposition='outside'
             )

trace1 = go.Bar(
             x= x,
             y= y2,
             marker={'color' : '#FFB300'},
             name = 'Closed Tickets',
             text=y2,
             textposition='outside'
              )    

trace2 = go.Bar(
             x= x,
             y= y3,
             marker={'color' : '#F7DC6F'},
             name = 'Cancelled Tickets',
             text=y3,
             textposition='outside'
              )  
    
layout = go.Layout(
                   title= 'Open Tickets by Status' , 
                   barmode = 'group',
                   width=900,
                   height=800,
                   xaxis_tickangle=-45
                  )


data = [trace0,trace1,trace2]
fig = go.Figure(data=data, layout=layout)

fig.show()
# Grouped Bar Chart with values displayed inside the bar using "auto" textposition 
x = ['Asif','Basit','John','Batista', 'Gabriel' , 'Paul' , 'Ravi'] 
y1 = [17,18,29,33,38,39,42]
y2 = [20,21,22,23,21,28,25]
y3 = [5,13,11,12,13,11,16]
trace0 = go.Bar(
             x= x,
             y= y1,
             marker= dict (color ='#FF6F00' ),
             name = 'Open Tickets',
             text=y1,
             textposition='auto'
             )

trace1 = go.Bar(
             x= x,
             y= y2,
             marker={'color' : '#FFB300'},
             name = 'Closed Tickets',
             text=y2,
             textposition='auto'
              )    

trace2 = go.Bar(
             x= x,
             y= y3,
             marker={'color' : '#F7DC6F'},
             name = 'Cancelled Tickets',
             text=y3,
             textposition='auto'
              )  
    

layout = go.Layout(
                   title=dict(text = "Tickets by Status",x=0.5,y=0.95,font_size=25), 
                   barmode = 'group',
                   width=980,
                   height=800,
                   xaxis_tickangle=-45,
                   xaxis_tickfont_size=14,
                   yaxis=dict(
                               title='Number of Tickets',
                               titlefont_size=16,
                               tickfont_size=14,
                              ),
   
                   xaxis=dict(
                               title='Assignee',
                               titlefont_size=16,
                               tickfont_size=14,
                              ), 
                  legend=dict(
                               x=0,
                               y=1,
                               bgcolor='rgba(255, 255, 255, 0)',
                               bordercolor='rgba(255, 255, 255, 0)'
                              ),
                  bargap=0.15, # gap between bars of adjacent location coordinates.
                  bargroupgap=0.08 # gap between bars of the same location coordinate.
                 )


data = [trace0,trace1,trace2]
fig = go.Figure(data=data, layout=layout)

fig.show()<jupyter_output><empty_output><jupyter_text>Bar Plot using Plotly Express<jupyter_code>#Simple Bar plot using px.bar

x = np.arange(1,10)
y = np.arange(20,110,10)
fig = px.bar(x=x, y=y)
fig.show()
x = np.arange(1,10)
y = np.arange(20,110,10)
fig = px.bar(x=x, y=y,color=y)
fig.layout.title.text = "Bar Plot - Plotly Express"
fig.update_traces(textposition='outside')
fig.show()
x = np.arange(1,10)
y = np.arange(20,110,10)
fig = px.bar(x=x, y=y,color=y,text=y)
fig.layout.title.text = "Bar Plot - Plotly Express"
fig.update_traces(textposition='outside')
fig.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13595266586890042, 'fraction_numerical': 0.056508443026193324, 'mean_word_length': 1.3398662311401461, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '340274', 'license': 'MIT', 'n_tokens_mistral': 5335, 'n_tokens_neox': 4788, 'n_words': 953, 'path': 'Plotly/.ipynb_checkpoints/Bar Chart-checkpoint.ipynb', 'repo_name': 'nibinkjoseph/Data-Visualization', 'size': '15042'}