Библиотека Python Seaborn не работает должным образом в Visual Studio
Я попытался запустить скрипт Python в Visual Studio, который включает в себя библиотеки Python matplotlib и seaborn. Скрипт, включающий matplotlib, работает только правильно и отображает график, однако скрипт, включающий seaborn, ничего не делает (без ошибок). Я установил библиотеки, установив Anaconda.
Код, который работает должным образом, является примером с сайта matplotlib:
"""
========
Barchart
========
A bar plot with errorbars and height labels on individual bars
"""
import numpy as np
import matplotlib.pyplot as plt
N = 5
men_means = (20, 35, 30, 35, 27)
men_std = (2, 3, 4, 1, 2)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind, men_means, width, color='r', yerr=men_std)
women_means = (25, 32, 34, 20, 25)
women_std = (3, 5, 2, 3, 3)
rects2 = ax.bar(ind + width, women_means, width, color='y', yerr=women_std)
# add some text for labels, title and axes ticks
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width / 2)
ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5'))
ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))
def autolabel(rects):
"""
Attach a text label above each bar displaying its height
"""
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
'%d' % int(height),
ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
plt.show()
Если я запускаю код:
# First, we'll import pandas, a data processing and CSV file I/O library
import pandas as pd
# We'll also import seaborn, a Python graphing library
import warnings # current version of seaborn generates a bunch of warnings that we'll ignore
warnings.filterwarnings("ignore")
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="dark", color_codes=True)
# Next, we'll load the Iris flower dataset, which is in the "../input/" directory
iris = pd.read_csv("Iris.csv") # the iris dataset is now a Pandas DataFrame
# Let's see what's in the iris data - Jupyter notebooks print the result of the last thing you do
iris.head(1000)
# Press shift+enter to execute this cell
в Visual Studio ничего не происходит, но выполняется код на
https://www.kaggle.com/benhamner/python-data-visualizations
дает правильный вывод.
Набор данных, который я использовал, можно найти по адресу:
https://www.kaggle.com/benhamner/python-data-visualizations/data
Как я могу заставить Seaborn работать в Visual Studio?
1 ответ
Здесь вы сравниваете два совершенно разных кода. Первый код создает сюжет в новом окне. Второй код не имеет вывода. Как говорится в комментарии внутри кода: "Записные книжки Jupyter распечатывают результат последнего, что вы делаете".
Visual Studio не делает этого; или, в общем, Python не делает этого. Если вы хотите напечатать что-то в Python, вам нужно print
утверждение или функция.
В питоне 2 делай
print iris.head(1000)
В питоне 3 делай
print (iris.head(1000))
Все это не имеет ничего общего с морским рожком.