matplotlib plt неправильно устанавливает xlabel / ylabel на scatterplot - PullRequest
0 голосов
/ 27 января 2020

Я создаю геоплот и пытаюсь установить свои xlabels и ylabels. Это показывает только ylabel, но не xlabel. Вот минимальный воспроизводимый пример.

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

d = {
    'College': ['East Los Angeles College', 'Santa Monica Ccollege', 'American River College', 'Santa Ana College', 'Mount San Antonio College'],
    'Total Enrollment': [36606, 29999, 29701, 28698, 28481], 
    'Latitude': [34.0414, 34.0166, 38.6511, 33.7580, 34.0482],
    'Longitude': [-118.1503, -118.4704, -121.3467, -117.8889, 117.8451]
}
df = pd.DataFrame(data=d)
ax2 = df.plot.scatter(x='Longitude', y='Latitude',
                     s=df['Total Enrollment']/100, label='Enrollment',
                     c='Total Enrollment', cmap=plt.get_cmap("jet"),
                     colorbar=True, alpha=0.5, figsize=(15,12))

plt.ylabel("Latitude", fontsize=14)
plt.xlabel("Longitude", fontsize=14)

plt.legend(fontsize=16)
plt.show()

enter image description here

1 Ответ

1 голос
/ 27 января 2020

Мне кажется, что добавление следующих строк работает:

fig, ax = plt.subplots()
...
df.plot.scatter(..., ax=ax)

ax.set_ylabel("Latitude", fontsize=14)
ax.set_xlabel("Longitude", fontsize=14)

Хотя, как отмечалось в , этот вопрос , вызов plt.subplots и указание осей, похоже, является недостающим звеном.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...