Skip to content

Support adjusting the element size of legend #270

@zxdawn

Description

@zxdawn

Description

Sometimes, the plotted scatter size is small or big, we need to adjust the size in the legend to make it easier to read.

Steps to reproduce

import proplot as pplt
import numpy as np

def rand_data():
    return np.random.uniform(low=0., high=1., size=(100,))

# Generate data.
x1, y1 = [rand_data() for i in range(2)]
x2, y2 = [rand_data() for i in range(2)]

fig, axs = pplt.subplots()
s1 = axs.scatter(x1, y1, marker='o', label='first', s=2, c='b')
s2 = axs.scatter(x2, y2, marker='o', label='second', s=3, c='r')
axs.legend([s1, s2], loc='r', ncols=1)

Expected behavior:
Support size=() in axs.legend().

Actual behavior:
image

I have to adjust the scatter size in the legend manually:

legend = axs.legend([s1, s2], loc='r', ncols=1)

legend.legendHandles[0]._sizes = [30]
legend.legendHandles[1]._sizes = [30]

image

Equivalent steps in matplotlib

import matplotlib.pyplot as plt
import numpy as np

def rand_data():
    return np.random.uniform(low=0., high=1., size=(100,))

# Generate data.
x1, y1 = [rand_data() for i in range(2)]
x2, y2 = [rand_data() for i in range(2)]

plt.figure()
plt.scatter(x1, y1, marker='o', label='first', s=2., c='b')
plt.scatter(x2, y2, marker='o', label='second', s=3., c='r')
# Plot legend.
lgnd = plt.legend(loc="lower right", scatterpoints=1, fontsize=10)
lgnd.legendHandles[0]._sizes = [30]
lgnd.legendHandles[1]._sizes = [30]

Proplot version

0.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions