Matplotlip Bar Syntax.

import codecademylib
from matplotlib import pyplot as plt

drinks = ["cappuccino""latte""chai""americano""mocha""espresso"]
sales1 =  [917656665227]
sales2 = [658236683840]

#Paste the x_values code here
n = 1  # This is our first dataset (out of 2)
t = 2 # Number of datasets
d = 6 # Number of sets of bars
w = 0.8 # Width of each bar
store1_x = [t*element + w*n for element
             in range(d)]
plt.bar(store1_x,sales1)
n = 2  # This is our second dataset (out of 2)
t = 2 # Number of datasets
d = 6 # Number of sets of bars
w = 0.8 # Width of each bar
store2_x = [t*element + w*n for element
             in range(d)]
plt.bar(store2_x,sales2)
plt.show()

Syntax for Stack Chart
plt.bar(range(len(drinks)), sales1)
plt.bar(range(len(drinks)), sales2bottom=sales1)

plt.legend(["Location 1""Location 2"])

plt.show()



Syntax to show error in bars -
drinks = ["cappuccino""latte""chai""americano""mocha""espresso"]
ounces_of_milk = [694090]
error = [0.60.90.400.90]

# Plot the bar graph here
plt.bar(range(len(drinks)),ounces_of_milk,yerr=error,capsize=5)

plt.show()


Syntax to use fill-in between:
plt.plot(months,revenue)
ax = plt.subplot()
ax.set_xticks(months)
ax.set_xticklabels(month_names)
y_lower = [0.9*i for i in revenue]
y_upper = [1.1*i for i in revenue]
plt.fill_between(months,y_lower,y_upper,alpha = 0.2)
plt.show()
months = x_value


Syntax to create a pie chart using legends and also display percentage to the nearest decimal using autopct

plt.pie(payment_method_freqs,autopct = '%0.1f%%')
plt.axis('equal')
plt.legend(payment_method_names)

Syntax to create a histogram and its various parameters for more visibility and understanding
use the keyword alpha, which can be a value between 0 and 1. This sets the transparency of the histogram. A value of 0 would make the bars entirely transparent. A value of 1 would make the bars completely opaque.

use the keyword histtype with the argument 'step' to draw just the outline of a histogram:

To solve this, we can normalize our histograms using normed=True. This command divides the height of each column by a constant such that the total shaded area of the histogram sums to 1.


plt.hist(sales_times1bins=20,alpha=0.4,normed=True)
#plot your other histogram here
plt.hist(sales_times2,alpha=0.4,Normed=True)
plt.hist(a, range=(55, 75), bins=20, histtype='step') plt.hist(b, range=(55, 75), bins=20, histtype='step')
We userange to set the range in between values in a histogram




























Comments

Popular posts from this blog

Binomial Test in Python

Slicing and Indexing in Python Pandas

Python Syntax and Functions Part2 (Summary Statistics)