【问题标题】:Can i make a scatter plot with string labels by matplotlib in python?我可以在 python 中通过 matplotlib 制作带有字符串标签的散点图吗?
【发布时间】:2022-01-05 16:59:26
【问题描述】:

我有一个二维整数数组,它表示类似热图的东西。我想将其打印为带有不同大小点的散点图。

例子:

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()

结果如下所示: Scatter plot

有什么方法可以改变x轴和y轴的范围和标签吗?我想把它们变成字符串。

我想让一个情节看起来像这样:Better scatter plot *(图像是在 gimp 中编辑的)

我尝试通过plt.xlim() 进行操作,还尝试将数据源更改为字符数组,但没有成功。

感谢您的任何建议。

【问题讨论】:

    标签: python string plot character scatter


    【解决方案1】:

    我想你想要plt.xticksplt.yticks

    例如:

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

    这应该允许您匹配您包含的已编辑绘图。

    【讨论】:

      猜你喜欢
      • 2019-06-04
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多