我正在尝试使用plugins.InteractiveLegendPlugin()可视化交互式绘图。但是,并非所有图例(从1到50的数字)都完整显示(仅显示1到19)。然后,我尝试使用fig.subplots_adjust(right=0.7, top=1)
调整图形,现在它显示更多的图例(1到21)。但仍然不完全,而且再也无法更改调整。
import mpld3
from mpld3 import plugins
from mpld3.utils import get_id
import collections
partial = df_mobile.iloc[::100, :]
img = plt.imread("StHimarkNeighborhoodMapNoLabels.png")
fig,ax = plt.subplots()
fig.set_size_inches(14,8,forward=True)
fig.suptitle("Location of Pollution", fontsize=20)
fig.subplots_adjust(right=0.7, top=1)
ax.imshow(img, extent=[-120, -119.711, 0, 0.2385])
plt.ylabel("Latitude",fontsize=15)
plt.xlabel("Longtitude",fontsize=15)
for val in range(1,51):
partial_filtered = partial[partial['Sensor-id']==val].filter(items=['Long','Lat'])
vis = ax.plot(partial_filtered['Long'], partial_filtered['Lat'].T, lw=2, alpha=0.8, label=val)
handles, labels = ax.get_legend_handles_labels()
plt.grid()
interactive_legend = plugins.InteractiveLegendPlugin(zip(handles,
labels),
labels,
alpha_unsel=0.5,
alpha_over=1.5,
start_visible=True)
plugins.connect(fig, interactive_legend)
plt.gca().set_ylim(0, 0.2385)
plt.gca().set_xlim(-120, -119.711)
mpld3.display()