Ask Your Question
1

What are the steps to adjust the dot size in a plot created with mpl-scatter-density?

asked 2022-09-13 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-12-05 11:00:00 +0000

scrum gravatar image
  1. Import the necessary packages:
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_scatter_density import ScatterDensity
  1. Create data points for x, y, and density values:
x = [1, 2, 3, 4, 5]
y = [1, 1, 2, 2, 2]
density = [5, 10, 20, 30, 40]
  1. Set up the scatter plot with mpl-scatter-density:
fig, ax = plt.subplots()
sc = ScatterDensity(ax, x, y, density)
  1. Create a colormap with the desired dot size:
cmap = cm.get_cmap('jet', 30) #create a color map using the 'jet' color scheme with 30 different colors
sizes = [20, 40, 60, 80, 100] #a list of five different dot sizes to correspond with the five different density values
  1. Update the scatter plot with the new colormap and dot sizes:
sc.scatter(s=100, marker='.', cmap=cmap, sizes=sizes, lw=0)

The sizes argument in sc.scatter() specifies the different dot sizes to be used for the different density levels. The s=100 argument sets the default size for the dots in the plot. Adjust the sizes argument and the s argument as needed to achieve the desired dot size.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-09-13 11:00:00 +0000

Seen: 11 times

Last updated: Dec 05 '22