Finding the right marker size for a scatter plot

后端 未结 1 894
野的像风
野的像风 2021-01-27 01:52

I want to plot a grid where each node in the grid is drawn by a dot, with a certain color code (taken from a vector stored in the node).

相关标签:
1条回答
  • 2021-01-27 02:46

    If you want to control the marker size precisely and have it scale with the figure, you can use a patch instead of a regular marker. Here's an example:

    from matplotlib import pyplot as plt
    from matplotlib.patches import Circle
    
    x = [1, 2, 3, 4, 5]
    y = [1, 3, 1, 2, 4]
    colors = [10, 215, 30, 100]
    
    cmap = plt.cm.jet
    fig = plt.figure()
    ax = fig.add_subplot(111, aspect='equal')
    
    for (x, y, c) in zip(x, y, colors):
        ax.add_artist(Circle(xy=(x, y), radius=0.5, color=cmap(c)))      
    
    ax.set_xlim(0, 6)
    ax.set_ylim(0, 6)
    plt.show()
    

    You could also use a rectangle instead of a circle.

    0 讨论(0)
提交回复
热议问题