程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python draws a lollipop chart

編輯:Python
import matplotlib.pyplot as plt
import numpy as np
x=range(1,41)
values=np.random.uniform(size=40)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
plt.stem(x, values)
plt.ylim(0, 1.2)
plt.show()
plt.gca()

import matplotlib.pyplot as plt
import numpy as np
x=range(1,41)
values=np.random.uniform(size=40)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
plt.stem(values)
plt.ylim(0, 1.2)
plt.show()
plt.gca()

 

import matplotlib.pyplot as plt
import numpy as np
x=range(1,41)
values=np.random.uniform(size=40)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
(markerline, stemlines, baseline) = plt.stem(x, values)
plt.setp(baseline, visible=False)
plt.ylim(0, 1.2)
plt.show()
plt.gca()

 

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.DataFrame({'group':map(chr, range(65, 85)), 'values':np.random.uniform(size=20) })
ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)
plt.stem(ordered_df['values'])
plt.xticks( my_range, ordered_df['group'])
plt.show()
plt.gca()

 

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.DataFrame({'group':map(chr, range(65, 85)), 'values':np.random.uniform(size=20) })
ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)
plt.hlines(y=my_range, xmin=0, xmax=ordered_df['values'], color='skyblue')
plt.plot(ordered_df['values'], my_range, "D")
plt.yticks(my_range, ordered_df['group'])
plt.show()
plt.gca()

 

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
df = pd.DataFrame({'group':map(chr, range(65, 85)), 'values':np.random.uniform(size=20) })
ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)
plt.hlines(y=my_range, xmin=0, xmax=ordered_df['values'], color='skyblue')
plt.plot(ordered_df['values'], my_range, "D")
plt.yticks(my_range, ordered_df['group'])
plt.show()
plt.gca()

 

import matplotlib.pyplot as plt
import numpy as np
values=np.random.uniform(size=40)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
plt.stem(values, markerfmt=' ')
plt.show()

 

import matplotlib.pyplot as plt
import numpy as np
values=np.random.uniform(size=40)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
(markers, stemlines, baseline) = plt.stem(values)
plt.setp(markers, marker='D', markersize=10, markeredgecolor="orange", markeredgewidth=2)
plt.show()

 

import matplotlib.pyplot as plt
import numpy as np
values=np.random.uniform(size=100)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
plt.stem(values, markerfmt=' ', bottom=0.5)
plt.show()
plt.gca()

 

import matplotlib.pyplot as plt
import numpy as np
values=np.random.uniform(size=100)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
(markers, stemlines, baseline) = plt.stem(values)
plt.setp(baseline, visible=False)
plt.show()
plt.gca()

 

import matplotlib.pyplot as plt
import numpy as np
values=np.random.uniform(size=100)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
plt.stem(values, basefmt=" ")
plt.show()
plt.gca()

 

import matplotlib.pyplot as plt
import numpy as np
values=np.random.uniform(size=100)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
(markers, stemlines, baseline) = plt.stem(values)
plt.setp(baseline, line, color="grey", linewidth=6)
plt.show()
plt.gca()

 

import matplotlib.pyplot as plt
import numpy as np
values=np.random.uniform(size=100)
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
(markers, stemlines, baseline) = plt.stem(values)
plt.setp(stemlines, line, color="olive", linewidth=0.5 )
plt.show()
plt.gca()

 

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
df = pd.DataFrame({'group':map(chr, range(65, 85)), 'values':np.random.uniform(size=20) })
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)
plt.hlines(y=my_range, xmin=0, xmax=ordered_df['values'], color='skyblue')
plt.plot(ordered_df['values'], my_range, "o")
plt.yticks(my_range, ordered_df['group'])
plt.title("A vertical lolipop plot", loc='left')
plt.xlabel('Value of the variable')
plt.ylabel('Group')
plt.show()
plt.gca()

 

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
df = pd.DataFrame({'group':map(chr, range(65, 85)), 'values':np.random.uniform(size=20) })
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)
my_color=np.where(ordered_df ['group']=='B', 'orange', 'skyblue')
my_size=np.where(ordered_df ['group']=='B', 70, 30)
plt.hlines(y=my_range, xmin=0, xmax=ordered_df['values'], color=my_color, alpha=0.4)
plt.scatter(ordered_df['values'], my_range, color=my_color, s=my_size, alpha=1)
plt.yticks(my_range, ordered_df['group'])
plt.title("What about the B group?", loc='left')
plt.xlabel('Value of the variable')
plt.ylabel('Group')
plt.show()
plt.gca()

 

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
value1=np.random.uniform(size=20)
value2=value1+np.random.uniform(size=20)/4
df = pd.DataFrame({'group':map(chr, range(65, 85)), 'value1':value1 , 'value2':value2 })
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
ordered_df = df.sort_values(by='value1')
my_range=range(1,len(df.index)+1)
plt.hlines(y=my_range, xmin=ordered_df['value1'], xmax=ordered_df['value2'], color='grey', alpha=0.4)
plt.scatter(ordered_df['value1'], my_range, color='skyblue', alpha=1, label='value1')
plt.scatter(ordered_df['value2'], my_range, color='green', alpha=0.4 , label='value2')
plt.legend()
plt.yticks(my_range, ordered_df['group'])
plt.title("Comparison of the value 1 and the value 2", loc='left')
plt.xlabel('Value of the variables')
plt.ylabel('Group')
plt.show()
plt.gca()

 

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x) + np.random.uniform(size=len(x)) - 0.2
my_color=np.where(y>=0, 'orange', 'skyblue')
plt.vlines(x=x, ymin=0, ymax=y, color=my_color, alpha=0.4)
plt.scatter(x, y, color=my_color, s=1, alpha=1)
plt.title("Evolution of the value of ...", loc='left')
plt.xlabel('Value of the variable')
plt.ylabel('Group')
plt.show()
plt.gca()

 

The blogger opened a new official account ,  I hope you can scan the code and pay attention , Thank you very much .

 

This article is from :https://github.com/holtzy/The-Python-Graph-Gallery/blob/master/PGG_notebook.py 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved