Matplotlib adding legend based on existing color series

前端 未结 2 1248
半阙折子戏
半阙折子戏 2020-12-01 19:54

I plotted some data using scatter plot and specified it as such:

plt.scatter(rna.data[\'x\'], rna.data[\'y\'], s=size,
                    c=rna.data[\'colors         


        
2条回答
  •  甜味超标
    2020-12-01 20:51

    Altair can be a great choice here.

    Continuous classes

    import matplotlib.pyplot as plt
    import numpy as np
    import pandas as pd
    
    df = pd.DataFrame(40*np.random.randn(10, 3), columns=['A', 'B','C'])
    
    from altair import *
    Chart(df).mark_circle().encode(x='A',y='B', color='C').configure_cell(width=200, height=150)
    

    Discrete classes

    df = pd.DataFrame(10*np.random.randn(40, 2), columns=['A', 'B'])
    df['C'] = np.random.choice(['alpha','beta','gamma','delta'], size=40)
    
    from altair import *
    Chart(df).mark_circle().encode(x='A',y='B', color='C').configure_cell(width=200, height=150)
    

提交回复
热议问题