欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python画气泡图

程序员文章站 2022-08-18 08:38:22
from matplotlib import pyplot as pltimport numpy as npmy_dpi=96plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)x = np.random.rand(15)y = x+np.random.rand(15)z = x+np.random.rand(15)z=z*zplt.scatter(x, y, s=z*2000, c=x, cmap="BuPu", alpha=....
from matplotlib import pyplot as plt
import numpy as np
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)

x = np.random.rand(15)
y = x+np.random.rand(15)
z = x+np.random.rand(15)
z=z*z
plt.scatter(x, y, s=z*2000, c=x, cmap="BuPu", alpha=0.4, edgecolors="grey", linewidth=2)
plt.show()

Python画气泡图

from matplotlib import pyplot as plt
import numpy as np
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)

x = np.random.rand(15)
y = x+np.random.rand(15)
z = x+np.random.rand(15)
z=z*z
plt.scatter(x, y, s=z*2000, c=x, cmap="plasma", alpha=0.4, edgecolors="grey", linewidth=2)
plt.show()

 Python画气泡图

from matplotlib import pyplot as plt
import numpy as np
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)

x = np.random.rand(80) - 0.5
y = x+np.random.rand(80)
z = x+np.random.rand(80)

plt.scatter(x, y, s=z*2000, c=x, cmap="PuOr_r", alpha=0.4, edgecolors="grey", linewidth=2)
plt.show()

 Python画气泡图

from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)

df = sns.load_dataset('iris')

df['species']=pd.Categorical(df['species'])
df['species'].cat.codes

plt.scatter(df['sepal_length'], df['sepal_width'], s=62, c=df['species'].cat.codes, cmap="Set1", alpha=0.9, linewidth=0)
plt.show()

 Python画气泡图

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

df=pd.DataFrame({'x': range(1,11), 'y1': np.random.randn(10), 'y2': np.random.randn(10)+range(1,11), 'y3': np.random.randn(10)+range(11,21), 'y4': np.random.randn(10)+range(6,16), 'y5': np.random.randn(10)+range(4,14), 'y6': np.random.randn(10)+range(2,12), 'y7': np.random.randn(10)+range(5,15), 'y8': np.random.randn(10)+range(4,14) })

possibilities = [u'seaborn-darkgrid', u'seaborn-notebook', u'classic', u'seaborn-ticks', u'grayscale', u'bmh', u'seaborn-talk', u'dark_background', u'ggplot', u'fivethirtyeight', u'_classic_test', u'seaborn-colorblind', u'seaborn-deep', u'seaborn-whitegrid', u'seaborn-bright', u'seaborn-poster', u'seaborn-muted', u'seaborn-paper', u'seaborn-white', u'seaborn-pastel', u'seaborn-dark', u'seaborn', u'seaborn-dark-palette']

my_dpi=96
plt.figure(figsize=(1000/my_dpi, 1000/my_dpi), dpi=my_dpi)

for n, v in enumerate(possibilities):
    plt.subplot(5 ,5, n + 1)
    
    for column in df.drop('x', axis=1):  
        plt.plot(df['x'], df[column], marker='', color='grey', linewidth=1, alpha=0.4)
    
    plt.plot(df['x'], df['y5'], marker='', color='orange', linewidth=4)
    
    plt.title(v, fontsize=10, fontweight=0, color='grey', loc='left')
    
    plt.tick_params(labelbottom='off')
    plt.tick_params(labelleft='off')

plt.show()

 Python画气泡图

本博主新开公众号, 希望大家能扫码关注一下,十分感谢大家。

Python画气泡图 

本文来自:https://github.com/holtzy/The-Python-Graph-Gallery/blob/master/PGG_notebook.py 

本文地址:https://blog.csdn.net/weixin_41869644/article/details/107449136