Home > Blockchain >  Can i make a scatter plot with string labels by matplotlib in python?
Can i make a scatter plot with string labels by matplotlib in python?

Time:01-06

I have 2D array of integers which represents something like a heatmap. I want to print it as scatter plot with dots of different sizes.

Example:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)
y = np.arange(10)
test_data = np.random.randint(low=0, high=500, size=(10, 10))

x, y = np.meshgrid(x, y)
plt.scatter(x, y, s=test_data[x, y])
plt.show()

Result looks like this: Scatter plot

Is there any way how to change range and labels of axis x and y? I want to change them into strings.

I want to make a plot looks like this: Better scatter plot *(image was edited in gimp)

I tried to do it by plt.xlim() and also I tried to change data source to arrays of characters, but no success.

Thanks for any suggestions.

CodePudding user response:

I think you want plt.xticks and plt.yticks

for example:

   x_ticks = ['a','b','c'...etc.]
   plt.xticks(x, x_ticks)

That should allow you to match the edited plot that you included.

  •  Tags:  
  • Related