【发布时间】:2019-07-11 14:44:23
【问题描述】:
我正在尝试将带有下标的注释添加到我的散点图中。问题是格式似乎不适用于两位数的整数。注解只是把第一个符号变成了下标,如下图所示。有谁知道如何解决这个问题?
import numpy as np
import matplotlib.pyplot as plt
import numpy.random as rnd
rnd.seed(1234)
#Generate data
n = 12 #Number of vehicles
N = [i for i in range(1,n+1)] #Set of vehicles
V = [0] + N #Set of all nodes
q = {i: rnd.randint(1,10) for i in N} #Number of goods to be transported to each customer
#Generate coordinates
loc_x = rnd.rand(len(V))*300
loc_y = rnd.rand(len(V))*500
plt.scatter(loc_x[1:], loc_y[1:], c='b')
for i in N:
plt.annotate('$q_{}={}$'.format(i, q[i]),(loc_x[i]+2, loc_y[i]))
【问题讨论】:
标签: python matplotlib annotations scatter-plot subscript