You are on page 1of 44

MATPLOT_LIB_AND_SEABORN

July 15, 2021

[1]: !pip install matplotlib seaborn --upgrade --quiet


!pip install plotly

Collecting plotly
Downloading plotly-5.1.0-py2.py3-none-any.whl (20.6 MB)
|��������������������������������| 20.6 MB 7.1 MB/s eta 0:00:01
|���������������� | 9.8 MB 7.1 MB/s eta 0:00:02
Collecting tenacity>=6.2.0
Downloading tenacity-8.0.0-py3-none-any.whl (22 kB)
Requirement already satisfied: six in /opt/conda/lib/python3.9/site-packages
(from plotly) (1.16.0)
Installing collected packages: tenacity, plotly
Successfully installed plotly-5.1.0 tenacity-8.0.0

[2]: import matplotlib.pyplot as plt


import pandas as pd
import seaborn as sns
%matplotlib inline

[24]: ## line chart


yield_apples=[12,14,16,17,18,20]
yield_oranges=[36,40,51,20,22,12]
plt.plot(yield_apples,'x-r');

1
[5]: ## x axis
years=[2020,2021,2022,2023,2024,2025]
plt.plot(years,yield_apples,'x-r');
plt.plot(years,yield_oranges,'x-b');
plt.xlabel('years')
plt.ylabel('production units')
plt.legend(['yield_oranges','yield_apples'])

[5]: <matplotlib.legend.Legend at 0x7fc17b7909a0>

2
[6]: ## changing figure size
plt.figure(figsize=(12,6))
plt.plot(years,yield_oranges,'o-r')

[6]: [<matplotlib.lines.Line2D at 0x7fc17b720cd0>]

3
[7]: ## sea born
sns.set_style("whitegrid")## see applying darkgrid
plt.plot(years,yield_oranges,'x-b');

[8]: ## scatterplot
flowers_df = sns.load_dataset("iris")

[9]: flowers_df

[9]: sepal_length sepal_width petal_length petal_width species


0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa
.. … … … … …
145 6.7 3.0 5.2 2.3 virginica
146 6.3 2.5 5.0 1.9 virginica
147 6.5 3.0 5.2 2.0 virginica
148 6.2 3.4 5.4 2.3 virginica
149 5.9 3.0 5.1 1.8 virginica

[150 rows x 5 columns]

[10]: plt.plot(flowers_df.sepal_length,flowers_df.sepal_width,);## linechart not␣


,→suitable

4
[11]: sns.scatterplot(flowers_df.sepal_length,flowers_df.sepal_width);

/opt/conda/lib/python3.9/site-packages/seaborn/_decorators.py:36: FutureWarning:
Pass the following variables as keyword args: x, y. From version 0.12, the only
valid positional argument will be `data`, and passing other arguments without an
explicit keyword will result in an error or misinterpretation.
warnings.warn(

5
[12]: ## add hue
sns.scatterplot(flowers_df.sepal_length,flowers_df.sepal_width,hue=flowers_df.
,→species,s=100);

/opt/conda/lib/python3.9/site-packages/seaborn/_decorators.py:36: FutureWarning:
Pass the following variables as keyword args: x, y. From version 0.12, the only
valid positional argument will be `data`, and passing other arguments without an
explicit keyword will result in an error or misinterpretation.
warnings.warn(

6
[13]: plt.figure(figsize=(12,6))
sns.scatterplot(flowers_df.sepal_length,flowers_df.sepal_width,hue=flowers_df.
,→species,s=100);

/opt/conda/lib/python3.9/site-packages/seaborn/_decorators.py:36: FutureWarning:
Pass the following variables as keyword args: x, y. From version 0.12, the only
valid positional argument will be `data`, and passing other arguments without an
explicit keyword will result in an error or misinterpretation.
warnings.warn(

7
[14]: ## histogram
flowers_df = sns.load_dataset("iris")
plt.hist(flowers_df.sepal_length)

[14]: (array([ 9., 23., 14., 27., 16., 26., 18., 6., 5., 6.]),
array([4.3 , 4.66, 5.02, 5.38, 5.74, 6.1 , 6.46, 6.82, 7.18, 7.54, 7.9 ]),
<BarContainer object of 10 artists>)

8
[15]: ## change the class interval lengths
plt.xlabel('magnitudes of sepal lengths')
plt.ylabel('no of units falling in the interval')
plt.hist(flowers_df.sepal_length,bins=[4,6,7,8])

[15]: (array([83., 54., 13.]),


array([4, 6, 7, 8]),
<BarContainer object of 3 artists>)

[16]: import numpy as np


setosa_df = flowers_df[flowers_df.species == 'setosa']
versicolor_df = flowers_df[flowers_df.species == 'versicolor']
virginica_df = flowers_df[flowers_df.species == 'virginica']
plt.hist(setosa_df.sepal_width, alpha=0.4, bins=np.arange(2, 5, 0.25));
plt.hist(versicolor_df.sepal_width, alpha=0.4, bins=np.arange(2, 5, 0.25));
plt.legend(['setosa','versicolor'])

[16]: <matplotlib.legend.Legend at 0x7fc1793f3040>

9
[17]: ## stacking multiple histogrms together

[18]: plt.hist([setosa_df.sepal_width, versicolor_df.sepal_width, virginica_df.


,→sepal_width],

bins=np.arange(2, 5, 0.25),
stacked=True);

plt.legend(['Setosa', 'Versicolor', 'Virginica']);

10
[19]: import jovian

[20]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>
[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on
https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[20]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

[21]: ## bar chart mr or less similar to line chart


years = range(2000, 2006)
apples = [0.35, 0.6, 0.9, 0.8, 0.65, 0.8]
oranges = [0.4, 0.8, 0.9, 0.7, 0.6, 0.8]
plt.bar(years,oranges)
plt.bar(years,apples,bottom=oranges)

[21]: <BarContainer object of 6 artists>

11
[22]: tips_df = sns.load_dataset("tips");

[23]: tips_df

[23]: total_bill tip sex smoker day time size


0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
.. … … … … … … …
239 29.03 5.92 Male No Sat Dinner 3
240 27.18 2.00 Female Yes Sat Dinner 2
241 22.67 2.00 Male Yes Sat Dinner 2
242 17.82 1.75 Male No Sat Dinner 2
243 18.78 3.00 Female No Thur Dinner 2

[244 rows x 7 columns]

[24]: plt.bar(tips_df.day,tips_df.total_bill,)

[24]: <BarContainer object of 244 artists>

12
[ ]: ## another reprsentation which shows the average also
sns.barplot('day', 'total_bill', hue='sex', data=tips_df);

/opt/conda/lib/python3.9/site-packages/seaborn/_decorators.py:36: FutureWarning:
Pass the following variables as keyword args: x, y. From version 0.12, the only
valid positional argument will be `data`, and passing other arguments without an
explicit keyword will result in an error or misinterpretation.
warnings.warn(

[26]: jovian.commit("MATPLOT LIB AND SEABORN")

[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on


https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[26]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

[27]: flights_df = sns.load_dataset("flights").pivot("month", "year", "passengers")

[28]: flights_df

[28]: year 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
month
Jan 112 115 145 171 196 204 242 284 315 340 360 417
Feb 118 126 150 180 196 188 233 277 301 318 342 391

13
Mar 132 141 178 193 236 235 267 317 356 362 406 419
Apr 129 135 163 181 235 227 269 313 348 348 396 461
May 121 125 172 183 229 234 270 318 355 363 420 472
Jun 135 149 178 218 243 264 315 374 422 435 472 535
Jul 148 170 199 230 264 302 364 413 465 491 548 622
Aug 148 170 199 242 272 293 347 405 467 505 559 606
Sep 136 158 184 209 237 259 312 355 404 404 463 508
Oct 119 133 162 191 211 229 274 306 347 359 407 461
Nov 104 114 146 172 180 203 237 271 305 310 362 390
Dec 118 140 166 194 201 229 278 306 336 337 405 432

[29]: sns.heatmap(flights_df);

[30]: sns.heatmap(flights_df, fmt="d", annot=True, cmap='Blues');

14
[31]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>
[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on
https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[31]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

[32]: ##so basic line,bar,hist,heatmap are over


## lets try to create multiple graphs inside a single page
fig,axes=plt.subplots(2,2,figsize=(20,20))
## 1st fig:line diagram:
axes[0,0].set_title("oranges vs line ")
axes[0,0].plot(years,yield_oranges)
axes[0,0].plot(years,yield_apples)
axes[0,0].set_xlabel('year no')
axes[0,0].set_ylabel('fruit')
axes[0,0].legend(['oranges','apples'])
## pass 2nd fig into sea born scatterplot:
axes[0,1].set_title('Sepal Length vs. Sepal Width')
sns.scatterplot(flowers_df.sepal_length,

15
flowers_df.sepal_width,
hue=flowers_df.species,
s=100,
ax=axes[0,1]);
## 3rd figure bar diagram
axes[1,0].set_title('bar daigram')
axes[1,0].bar(years,yield_oranges)
axes[1,0].set_xlabel('years')
axes[1,0].set_ylabel('years')
## 4th fig histogram
axes[1,1].set_title('histogram of oranges')
axes[1,1].hist(yield_oranges,bins=[10,20,30,40])
axes[1,1].set_xlabel('class intervals')
axes[1,1].set_ylabel('no of oranges belonging to that particular class')

/opt/conda/lib/python3.9/site-packages/seaborn/_decorators.py:36: FutureWarning:
Pass the following variables as keyword args: x, y. From version 0.12, the only
valid positional argument will be `data`, and passing other arguments without an
explicit keyword will result in an error or misinterpretation.
warnings.warn(

[32]: Text(0, 0.5, 'no of oranges belonging to that particular class')

16
[33]: import jovian

[34]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>
[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on
https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[34]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

17
[7]: fig=plt.figure(figsize=(8,8))
ax1=fig.add_subplot()
PH2S=[0,4,8,10,15,30,60,80,100,120,150]
Cl=[1000,2000,3000,4000,4500,5000,6000,7000,8000,10000]
TH2S=[80,80,80,80,80,71,53,41,29,18,0]
TCl=[120,105,90,75,67.5,60,60,60,60,60]
PH=[2,4,5.9,5,1.5,3]
PH2S1=[96.57,48.14,2.1315,23.925,108.6775,72.355]
plt.text(65,62,' Chloride SCC do not occur below 60C in this region ',fontsize=␣
,→10,color='green' )

plt.plot(15,80,'r*')
plt.annotate('H2S SCC occursafter 15psi',(15,80))
ax1.plot(PH2S,TH2S,'b-',label='Variation of Temp With PH2S')
ax1.set_ylabel('Temperature in Celsius ')
ax1.set_xlabel('Partial pressure of H2S in psi',color='b')
ax1.tick_params('x',colors='b')
ax2=ax1.twiny()
ax2.plot(Cl,TCl,'r',label='Variation of Temp With chlorion')
ax2.set_xlabel('Chlorine concentartion in mg/l',color='r')
ax2.tick_params('x',colors='r')
ax3=ax1.twinx()
ax3.plot(PH2S1,PH,'y',label='Variation of PH With PH2S')
ax3.set_ylabel('PH value ',color='y')
ax3.tick_params('y',colors='y')
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
h3, l3 = ax3.get_legend_handles_labels()
ax1.legend(h1+h2+h3, l1+l2+l3, loc=3)
fig.tight_layout()
plt.title(label="Service limits for 316 L ", fontsize=10,color='blue')
plt.show()

18
[8]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>
[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on
https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[8]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

[13]: fig=plt.figure(figsize=(8,8))
ax1=fig.add_subplot()

19
PH2S=[0,20,40,60,80,100,110,120,130,140,145,150]
Cl=[1000,5000,9000,10000,20000,30000,40000,50000,60000,70000,80000]
TH2S=[150,150,150,150,150,150,120,90,60,30,15,0]
TCl=[200,193,186,185,168,152,136,120,120,120,120]
PH=[2,4,5.9,5,1.5,3]
PH2S1=[96.57,48.14,2.1315,23.925,108.6775,72.355]
plt.text(90,125,' Chloride SCC do not occur below 120C in this region␣
,→',fontsize= 8,color='red' )

plt.plot(100,150,'r*')
plt.annotate('H2S SCC occursafter 100 psi',(100,150))
ax1.plot(PH2S,TH2S,'g-',label='Variation of Temp With PH2S')
ax1.set_ylabel('Temperature in Celsius ')
ax1.set_xlabel('Partial pressure of H2S in psi',color='g')
ax1.tick_params('x',colors='g')
ax2=ax1.twiny()
ax2.plot(Cl,TCl,'y',label='Variation of Temp With chlorion')
ax2.set_xlabel('Chlorine concentartion in mg/l',color='y')
ax2.tick_params('x',colors='y')
ax3=ax1.twinx()
ax3.plot(PH2S1,PH,'b',label='Variation of PH With PH2S')
ax3.set_ylabel('PH value ',color='b')
ax3.tick_params('y',colors='b')
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
h3, l3 = ax3.get_legend_handles_labels()
ax1.legend(h1+h2+h3, l1+l2+l3, loc=3)
fig.tight_layout()
plt.title(label="Service limits for 654 SMO Avesta ", fontsize=10,color='red')
plt.show()

20
[14]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>
[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on
https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[14]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

21
[18]: fig=plt.figure(figsize=(8,8))
ax1=fig.add_subplot()
PH2S=[0,0.5,1,1.6,2,10,20,50,60,80,110,130,150]
Cl=[1000,5000,9000,10000,20000,30000,40000,50000,60000,70000,80000]
TH2S=[200,200,200,200,200,189,176,135,122,95,54,27,0]
TCl=[230,219,208,206,179,153,126,100,100,100,100]
PH=[2,4,5.9,5,1.5,3]
PH2S1=[96.57,48.14,2.1315,23.925,108.6775,72.355]
plt.text(89,110,' Chloride SCC do not occur below 100 C in this region␣
,→',fontsize= 8,color='red' )

plt.plot(2,200,'r*')
plt.annotate('H2S SCC occursafter 2psi',(2,200))
ax1.plot(PH2S,TH2S,'g-',label='Variation of Temp With PH2S')
ax1.set_ylabel('Temperature in Celsius ')
ax1.set_xlabel('Partial pressure of H2S in psi',color='g')
ax1.tick_params('x',colors='g')
ax2=ax1.twiny()
ax2.plot(Cl,TCl,'orange',label='Variation of Temp With chlorion')
ax2.set_xlabel('Chlorine concentartion in mg/l',color='orange')
ax2.tick_params('x',colors='orange')
ax3=ax1.twinx()
ax3.plot(PH2S1,PH,'b',label='Variation of PH With PH2S')
ax3.set_ylabel('PH value ',color='b')
ax3.tick_params('y',colors='b')
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
h3, l3 = ax3.get_legend_handles_labels()
ax1.legend(h1+h2+h3, l1+l2+l3, loc=3)
fig.tight_layout()
plt.title(label="Service limits for 2205 Duplex ", fontsize=10,color='red')
plt.show()

22
[ ]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>

[12]: fig=plt.figure(figsize=(8,8))
ax1=fig.add_subplot()
PH2S=[0.2,0.5,1,1.5,2,2.5,3,5,10,20,40,60,80,100,120,140,150]
Cl=[1000,5000,10000,20000,40000,50000,100000,120000,200000]
TH2S=[232,232,232,232,232,232,232,228,220,205,173,141,110,78,47,15,0]
TCl=[250,245,238,225,199,186,120,120,120]
PH=[2,4,5.9,5,1.5,3]
PH2S1=[96.57,48.14,2.1315,23.925,108.6775,72.355]

23
plt.text(82,124,' Chloride SCC do not occur below 120 C in this region␣
,→',fontsize= 8,color='black' )

plt.plot(3,232,'r*')
plt.annotate('H2S SCC occursafter 3 psi',(3,232))
ax1.plot(PH2S,TH2S,'g-',label='Variation of Temp With PH2S')
ax1.set_ylabel('Temperature in Celsius ')
ax1.set_xlabel('Partial pressure of H2S in psi',color='g')
ax1.tick_params('x',colors='g')
ax2=ax1.twiny()
ax2.plot(Cl,TCl,'r',label='Variation of Temp With chlorion')
ax2.set_xlabel('Chlorine concentartion in mg/l',color='red')
ax2.tick_params('x',colors='red')
ax3=ax1.twinx()
ax3.plot(PH2S1,PH,'b',label='Variation of PH With PH2S')
ax3.set_ylabel('PH value ',color='b')
ax3.tick_params('y',colors='b')
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
h3, l3 = ax3.get_legend_handles_labels()
ax1.legend(h1+h2+h3, l1+l2+l3, loc=3)
fig.tight_layout()
plt.title(label="Service limits for Zeron 100 Super Duplex ",␣
,→fontsize=10,color='red')

plt.show()

24
[26]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>
[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on
https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[26]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

[14]: fig=plt.figure(figsize=(8,8))
ax1=fig.add_subplot()

25
PH2S=[30,200,330,360,400,500,600,700,800,1000]
Cl=[1000,10000,50000,100000]
TH2S=[232,204,199,191,149,135,135,135,135,135]
TCl=[232,232,232,232]
PH=[2,4,5.9,5,1.5,3]
PH2S1=[96.57,48.14,2.1315,23.925,108.6775,72.355]
plt.text(0,200,' Arya ',fontsize=70,bbox=dict(facecolor='red',alpha=0.5))
ax1.plot(PH2S,TH2S,'g-',label='Variation of Temp With PH2S')
ax1.set_ylabel('Temperature in Celsius ')
ax1.set_xlabel('Partial pressure of H2S in psi',color='g')
ax1.tick_params('x',colors='g')
ax2=ax1.twiny()
ax2.plot(Cl,TCl,'r',label='Variation of Temp With chlorion')
ax2.set_xlabel('Chlorine concentartion in mg/l',color='red')
ax2.tick_params('x',colors='red')
ax3=ax1.twinx()
ax3.plot(PH2S1,PH,'b',label='Variation of PH With PH2S')
ax3.set_ylabel('PH value ',color='b')
ax3.tick_params('y',colors='b')
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
h3, l3 = ax3.get_legend_handles_labels()
ax1.legend(h1+h2+h3, l1+l2+l3, loc=3)
fig.tight_layout()
plt.title(label="Service limits for Inconel 718 ", fontsize=10,color='red')
plt.show()

26
[9]: fig=plt.figure(figsize=(8,8))
ax1=fig.add_subplot()
PH2S=[30,200,330,360,400,500,600,700,800,1000]
Cl=[1000,10000,50000,100000]
TH2S=[232,204,199,191,149,135,135,135,135,135]
TCl=[232,232,232,232]
PH=[2,4,5.9,5,1.5,3]
PH2S1=[96.57,48.14,2.1315,23.925,108.6775,72.355]
plt.text(400,225,' Inconel 718 is immune to chloride SCC under 230 C␣
,→',fontsize= 10,color='green' )

plt.plot(500,135,'r*')
plt.annotate('Below 135C no H2S SCC occurs',(500,138),color='red')

27
ax1.plot(PH2S,TH2S,'g-',label='Variation of Temp With PH2S')
ax1.set_ylabel('Temperature in Celsius ')
ax1.set_xlabel('Partial pressure of H2S in psi',color='g')
ax1.tick_params('x',colors='g')
ax2=ax1.twiny()
ax2.plot(Cl,TCl,'r',label='Variation of Temp With chlorion')
ax2.set_xlabel('Chlorine concentartion in mg/l',color='red')
ax2.tick_params('x',colors='red')
ax3=ax1.twinx()
ax3.plot(PH2S1,PH,'b',label='Variation of PH With PH2S')
ax3.set_ylabel('PH value ',color='b')
ax3.tick_params('y',colors='b')
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
h3, l3 = ax3.get_legend_handles_labels()
ax1.legend(h1+h2+h3, l1+l2+l3, loc=3)
fig.tight_layout()
plt.title(label="Service limits for Inconel 718 ", fontsize=10,color='red')
plt.show()

28
[ ]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>

[34]: fig=plt.figure(figsize=(9,9))
ax1=fig.add_subplot()
PH2S1=[15,12.15,9.3,6.45,3.6,0.75,0.6,0.5,0.3,0.15,0]
Cl1=[0,1000,2000,3000,4000,5000,5000,5000,5000,5000,5000]
ax1.set_ylabel('Partial Pressure Of H2S in psi',color='r')
ax1.set_xlabel('chloride conc in mg/l',color='b')
plt.xscale("log")

29
plt.text(1000,4,' S 316 L operating zone ',fontsize=␣
,→10,color='black',bbox=dict(facecolor='green',alpha=0.5 ))

ax1.plot(Cl1,PH2S1,'g--')
PH2S2=[100,92,84,76,68,60,50,30,20,0]
Cl2=[0,10000,20000,30000,40000,50000,50000,50000,50000,50000]
plt.text(6000,60,' S 654 SMO operating zone ',fontsize=␣
,→10,color='black',bbox=dict(facecolor='red',alpha=0.5 ))

ax1.plot(Cl2,PH2S2,'r--')
PH2S3=[2,2,2,2,2,2,1,0.9,0.7,0.6,0,-1]
Cl3=[0,10000,20000,30000,40000,50000,50000,50000,50000,50000,50000,50000]
ax1.plot(Cl3,PH2S3,'y--')
plt.text(10000,-1,' Duplex 2205 operating zone ',fontsize=␣
,→10,color='black',bbox=dict(facecolor='yellow',alpha=0.5 ))

PH2S4=[3.5,3.5,3.5,3.5,3.5,3.5,3.5,3.5,3.5,3,2,1.5,0]
Cl4=[0,10000,20000,30000,40000,50000,80000,90000,100000,100000,100000,100000,100000]
ax1.plot(Cl4,PH2S4,'b--')
plt.text(50000,-5,' SuperDuplex Zeron100 operating zone ',fontsize=␣
,→10,color='black',bbox=dict(facecolor='blue',alpha=0.5 ))

plt.axhline(y=200,color='pink',linestyle='-')
plt.axvline(x=500000,color='pink',linestyle='-')
plt.text(50000,175,'Inconel718 operating zone ',fontsize=␣
,→10,color='black',bbox=dict(facecolor='pink',alpha=0.5 ))

fig.tight_layout()
plt.title(label="Stress Cracking Operating zones ", fontsize=10,color='blue')
plt.show()

30
[3]: ## Temperature chloride limits laboratory results
fig=plt.figure(figsize=(9,9))
ax=fig.add_subplot()
Cl316L=[2.39207E-05,2.62017E-05,2.83329E-05,3.14515E-05,3.87203E-05,5.
,→72201E-05,0.000101501,0.000280139,0.001371507,0.008270292,0.015431792,0.

,→027703252,0.050354592,0.091568728,0.158008656,0.26916641]

T316L=[244.4601,203.53212,183.89148,152.51436,127.8438,104.28102,83.5326,64.
,→49076,53.26326,51.58662,52.60458,53.71236,53.71236,53.17344,53.71236,53.

,→71236]

ax.set_ylabel('Temperature in Celsius',color='r')
ax.set_xlabel('chloride conc in ppm',color='b')
plt.xscale("log")

31
ax.plot(Cl316L, T316L, marker='o', c='g', ls='-', lw=2, ms=8, mew=2, mec='navy')
Cl2205=[0.0025357,0.00304095,0.00263681,0.003203198,0.004048271,0.006295845,0.
,→009795762,0.018755177,0.029942828,0.049074022,0.101553912,0.158008656,0.

,→335670429,0.535901199,0.901220372]

T2205=[246.79572,223.29282,245.11908,222.72396,208.74198,199.78992,193.
,→08336,186.91572,181.31694,177.96366,171.2571,169.0116,164.5206,162.30504,158.

,→92182]

ax.plot(Cl2205, T2205, marker='s', c='r', ls='-', lw=2, ms=8, mew=2, mec='navy')


Cl32760=[0.081433751,0.150005178,0.233287084,0.310563942,0.435297547,0.
,→550138362,0.677283412,1.012917251]

T32760=[299.4,287.09466,279.25038,272.54382,264.13068,261.91512,255.74748,252.
,→96306]

ax.plot(Cl32760, T32760, marker='o', c='y', ls='-', lw=2, ms=8, mew=2,␣


,→mec='navy')

Cl654=[0.001591656,0.002036708,0.002557512,0.003271128,0.00403084,0.00496471,0.
,→00611494,0.007535121,0.00910747,0.011875945,0.015780814,0.020577843,0.

,→027343939,0.037026538,0.048281811,0.062958445,0.083659493,0.109090183,0.

,→153468434,0.207812225,0.27098268,0.353355597,0.497101836,0.648210123,0.

,→946958157,1.25832268,1.909802107,2.68548039,3.777942798,5.733921219,9.

,→935355203,16.57042745,26.36980559]

T654=[268.96917,260.88386,254.28419,248.39877,242.51335,235.91368,231.5139,227.
,→08555,221.94295,218.28599,213.88621,210.9435,208.00079,206.54372,203.

,→60101,202.11537,199.91548,198.45841,197.71559,194.77288,195.5157,192.

,→57299,194.05863,194.05863,192.57299,192.57299,192.57299,192.57299,192.

,→57299,192.57299,192.57299,192.57299,195.5157]

ax.plot(Cl654, T654, marker='s', c='b', ls='-', lw=2, ms=8, mew=2, mec='navy')


fig.tight_layout()
plt.title(label="Temperature Chloride limits laboratory results for alloy␣
,→steels ", fontsize=15,color='cyan')

plt.legend(['316L', '2205 duplex','S32760 Super duplex','6540 SMO Super␣


,→Austenite'])

plt.show()

32
[6]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>
[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on
https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[6]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

33
[16]: ## CCT / CPT laboratory results for alloy steels
fig=plt.figure(figsize=(9,9))
ax=fig.add_subplot()
Cl316L1=[103.5102028,
112.5750585,
121.8158144,
131.8454213,
146.9643714,
160.6085738,
179.0258459,
199.5550596,
220.2493219,
260.5149335,
299.133567,
330.1543215,
364.3919908,
410.2144969,
448.4020155,
475.7060807,
504.7888313,
548.8692133,
]
CCT316L=[67.915208,
65.308802,
63.39566,
61.142552,
58.016198,
55.409792,
52.46342,
49.510382,
46.037396,
41.351198,
37.53158,
34.585208,
31.805486,
28.3325,
25.89941,
23.992934,
22.259774,
20.693264,
]
Cl316L2=[202.5608198,
211.7550508,
222.4383948,
238.3833724,
252.8989966,
265.7192196,

34
281.8993764,
299.133567,
314.2975617,
333.4357476,
350.3386247,
382.8641345,
410.2144969,
431.0095234,
457.2545262,
485.2092232,
509.8059617,
546.224567,
585.2447794,
621.0242841,
672.0012402,
713.0846849,
749.0608231,
810.7341425,
877.2834866,
944.7215103,
]
CPT316L=[85.966736,
84.753524,
82.49375,
79.367396,
76.940972,
74.507882,
72.074792,
69.821684,
67.388594,
65.135486,
63.049028,
58.882778,
56.109722,
54.023264,
51.423524,
49.16375,
46.73066,
43.784288,
41.004566,
38.051528,
35.278472,
32.49875,
30.412292,
26.945972,
23.992934,
20.693264,

35
]
Cl22051=[205.375536,
208.4210236,
226.6212646,
257.5954126,
295.7132356,
332.899348,
382.1603122,
430.1182565,
479.3304268,
523.831562,
601.3458256,
663.7066011,
746.9962656,
840.7380912,
974.7394319,
1086.264675,
1297.32559,
1489.298058,
1709.677758,
1924.228113,
2187.227821,
2486.173812,
2840.314845,
]
CCT2205=[85.106822,
83.89361,
81.82715,
78.367496,
74.914508,
72.154784,
69.048428,
66.108722,
63.86228,
60.755924,
58.336166,
55.749758,
52.983368,
50.56361,
46.59734,
43.83095,
39.858014,
36.058394,
33.471986,
30.53228,
27.252608,
24.146252,

36
20.86658,
]
Cl22052=[3459.156963,
3616.168019,
3836.363478,
4110.418742,
4404.051475,
4626.242146,
4956.723347,
5259.757416,
5580.034209,
5978.6507,
6280.282145,
6728.921694,
7068.405379,
7573.345464,
8034.501105,
8608.455406,
9315.082931,
9980.517144,
10799.77075,
11344.63457,
12155.05226,
12771.22901,
13548.89382,
]
CPT2205=[85.966736,
83.553644,
80.613938,
77.854214,
75.087824,
72.3281,
69.56171,
66.455354,
63.348998,
60.755924,
57.989534,
55.056494,
52.29677,
49.183748,
46.077392,
43.657634,
40.204646,
37.09829,
33.645302,
31.39886,
28.119188,

37
25.526114,
23.279672,
]
Cl6541=[586.7273233,
676.8097309,
746.9962656,
840.7380912,
974.7394319,
1097.061133,
1198.912513,
1336.086618,
1474.641496,
1643.363255,
1850.017146,
2061.687675,
2253.095181,
2486.173812,
2716.990699,
3057.950459,
3375.066092,
3688.40792,
4110.418742,
4536.677459,
5005.988556,
5580.034209,
6157.278679,
6795.800902,
7353.636163,
8195.005694,
8608.455406,
9088.636592,
8867.695081,
]
CCT654=[85.966736,
83.033696,
80.440622,
77.680898,
74.574542,
71.46152,
69.048428,
66.975302,
63.688964,
61.622504,
58.856114,
56.782988,
54.36323,
52.123454,

38
50.050328,
46.937306,
44.350898,
42.451088,
40.03133,
37.271606,
35.19848,
32.43209,
30.018998,
27.945872,
25.69943,
23.626304,
22.246442,
20.519948,
20.693264,
]
Cl6542=[8316.528391,
8780.425835,
9407.666171,
9787.292954,
10383.26014,
11015.51691,
11686.27302,
12275.86214,
13023.36311,
13819.55899,
14661.05864,
15553.79884,
16830.53687,
17679.66143,
18942.62942,
19702.4877,
21319.77204,
23069.81163,
24717.83152,
26746.80179,
29229.98035,
31009.85034,
32253.76908,
34391.34408,
34217.7634,
]
CPT654=[86.313368,
83.89361,
81.480518,
79.06076,
76.301036,

39
73.534646,
71.288204,
68.355164,
65.935406,
62.82905,
59.722694,
56.956304,
54.19658,
51.603506,
48.837116,
46.59734,
42.79772,
38.9981,
35.545112,
32.085458,
28.119188,
25.352798,
22.93304,
20.519948,
20.346632,
]
ax.set_ylabel('Temperature in Celsius',color='r')
ax.set_xlabel('chloride conc in ppm',color='b')
plt.xscale("log")
ax.plot(Cl316L1, CCT316L, marker='x', c='c', ls='-', lw=2, ms=8, mew=2,␣
,→mec='navy')

ax.plot(Cl316L2, CPT316L, marker='o', c='g', ls='-', lw=2, ms=8, mew=2,␣


,→mec='navy')

ax.plot(Cl22051, CCT2205, marker='s', c='r', ls='-', lw=2, ms=8, mew=2,␣


,→mec='navy')

ax.plot(Cl22052, CPT2205, marker='v', c='b', ls='-', lw=2, ms=8, mew=2,␣


,→mec='navy')

ax.plot(Cl6541, CCT654, marker='*', c='y', ls='-', lw=2, ms=8, mew=2,␣


,→mec='navy')

ax.plot(Cl6542, CPT654, marker='D', c='orange', ls='-', lw=2, ms=8, mew=2,␣


,→mec='navy')

fig.tight_layout()
plt.title(label=" CCT/CPT as a function of chloride ppm ",␣
,→fontsize=15,color='blue')

plt.legend(['CCT for 316L', 'CPT for 316L','CCT for 2205 duplex','CPT for 2205␣
,→duplex','CCT for 654 SMO','CPT for 654 SMO'])

plt.show()

40
[17]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>
[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on
https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[17]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

41
[3]: import plotly.graph_objects as go
import numpy as np
from scipy.interpolate import griddata

[11]: fig=plt.figure(figsize=(20,20))
z=[150,120,93,90,60]
y=[1.5,14.5,1.6,145,150]
x=[1000,2000,4000,1001,5000]

xi=np.linspace(0,6000,500)
yi=np.linspace(0,150,500)
xy=[(x[i],y[i]) for i in range(len(x))]

X, Y=np.meshgrid(xi, yi)
Z=griddata(xy,z,(X,Y),method="linear")

fig = go.Figure(data=[go.Surface(z=Z, x=X, y=Y)])


fig.update_layout(title='316 L Steel')
fig.update_layout(scene=dict(xaxis_title='Chloride(mg/L)',yaxis_title='Pressure␣
,→of Hydrogen sulfide(psi)',zaxis_title='Temperature(celsius)'))

fig.show()

<Figure size 1440x1440 with 0 Axes>

[13]: fig=plt.figure(figsize=(20,20))
z=[121,150,200]
y=[100,45,15]
x=[50000,30000,10000]

xi=np.linspace(5000,60000,500)
yi=np.linspace(0,200,500)
xy=[(x[i],y[i]) for i in range(len(x))]

X, Y=np.meshgrid(xi, yi)
Z=griddata(xy,z,(X,Y),method="linear")

fig = go.Figure(data=[go.Surface(z=Z, x=X, y=Y)])


fig.update_layout(title='654 SMO Steel')
fig.update_layout(scene=dict(xaxis_title='Chloride(mg/L)',yaxis_title='Pressure␣
,→of Hydrogen sulfide(psi)',zaxis_title='Temperature(celsius)'))

fig.show()

<Figure size 1440x1440 with 0 Axes>

[15]: jovian.commit("MATPLOT LIB AND SEABORN")

<IPython.core.display.Javascript object>

42
[jovian] Updating notebook "arya26cook/matplot-lib-and-seaborn" on
https://jovian.ai
[jovian] Committed successfully! https://jovian.ai/arya26cook/matplot-lib-and-
seaborn

[15]: 'https://jovian.ai/arya26cook/matplot-lib-and-seaborn'

[ ]: ## CCT CPT variation with PREN


fig=plt.figure(figsize=(9,9))
ax=fig.add_subplot()
CCT=[-5.99756,
-2.31591,
4.57482,
8.71805,
12.3997,
15.61977,
19.29043,
24.35682,
28.95064,
30.78597,
35.85236,
39.52302,
41.83092,
44.12783,
47.79849,
51.94172,
56.53554,
60.67877,
64.36042,
]
CPT=[4.12423,
9.64121,
13.31187,
17.91668,
22.04892,
28.02748,
33.09387,
39.9846,
45.50158,
49.18323,
53.32646,
59.75561,
64.822,
70.33898,
75.39438,
]
PREN1=[25.52,

43
26.82,
29.768,
31.85,
33.236,
34.798,
36.706,
38.44,
40.346,
42.254,
43.642,
45.376,
46.936,
48.15,
49.71,
51.098,
53.352,
54.914,
56.82,
]
PREN2=[22.398,
24.22,
25.954,
27.168,
29.076,
30.982,
32.544,
34.798,
36.706,
38.44,
40,
41.734,
43.988,
45.722,
47.456,
]
ax.set_ylabel('Temperature in Celsius',color='r')
ax.set_xlabel('Pitting Resistance Equivalent number',color='b')
ax.plot(, PREN1, marker='o', c='g', ls='-', lw=2, ms=8, mew=2, mec='navy')
ax.plot(CPT, PREN2, marker='s', c='r', ls='-', lw=2, ms=8, mew=2, mec='navy')
fig.tight_layout()
plt.title(label="CCT and CPT variaton with PREN ", fontsize=15,color='cyan')
plt.legend(['CCT', 'CPT'])
plt.show()

44

You might also like