Возникли проблемы при построении Lineplot в библиотеке Seaborn - PullRequest
1 голос
/ 16 февраля 2020

enter image description here Я хотел бы попросить некоторую помощь здесь. Я использую seaborn в Python для построения многострочных графиков, но, к сожалению, я получаю ошибки. Однако когда я использовал предварительно загруженные наборы данных в seaborn, такие как наборы данных fMRI, все прошло хорошо.

Ниже приведен код, который я использовал:

import seaborn as sns; sns.set()
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

df = pd.read_csv("ucc.csv")
df

df = sns.load_dataset("ucc")
ax = sns.lineplot(x="hours", y="viability", data=ucc)

Это ошибка, которую я получаю, когда запускаю приведенный выше код:

HTTPError                                 Traceback (most recent call last)
<ipython-input-3-07a022f8777e> in <module>
----> 1 df = sns.load_dataset("ucc")
      2 ax = sns.lineplot(x="hours", y="viability", data=ucc)

~/miniconda3/lib/python3.7/site-packages/seaborn/utils.py in load_dataset(name, cache, data_home, **kws)
    434                                   os.path.basename(full_path))
    435         if not os.path.exists(cache_path):
--> 436             urlretrieve(full_path, cache_path)
    437         full_path = cache_path
    438 

~/miniconda3/lib/python3.7/urllib/request.py in urlretrieve(url, filename, reporthook, data)
    245     url_type, path = splittype(url)
    246 
--> 247     with contextlib.closing(urlopen(url, data)) as fp:
    248         headers = fp.info()
    249 

~/miniconda3/lib/python3.7/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    220     else:
    221         opener = _opener
--> 222     return opener.open(url, data, timeout)
    223 
    224 def install_opener(opener):

~/miniconda3/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)
    529         for processor in self.process_response.get(protocol, []):
    530             meth = getattr(processor, meth_name)
--> 531             response = meth(req, response)
    532 
    533         return response

~/miniconda3/lib/python3.7/urllib/request.py in http_response(self, request, response)
    639         if not (200 <= code < 300):
    640             response = self.parent.error(
--> 641                 'http', request, response, code, msg, hdrs)
    642 
    643         return response

~/miniconda3/lib/python3.7/urllib/request.py in error(self, proto, *args)
    567         if http_err:
    568             args = (dict, 'default', 'http_error_default') + orig_args
--> 569             return self._call_chain(*args)
    570 
    571 # XXX probably also want an abstract factory that knows when it makes

~/miniconda3/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    501         for handler in handlers:
    502             func = getattr(handler, meth_name)
--> 503             result = func(*args)
    504             if result is not None:
    505                 return result

~/miniconda3/lib/python3.7/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    647 class HTTPDefaultErrorHandler(BaseHandler):
    648     def http_error_default(self, req, fp, code, msg, hdrs):
--> 649         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    650 
    651 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 404: Not Found

1 Ответ

0 голосов
/ 16 февраля 2020

Позвольте мне разбить то, что вы сделали, чтобы, возможно, вы могли лучше понять, что происходит; См. Комментарии, встроенные в ваш код.

import seaborn as sns; sns.set()
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

df = pd.read_csv("ucc.csv"). # Loads the csv file locally into a pandas dataframe
df  # Prints the head of that dataframe

# This command specifically loads datasets from [github](https://github.com/mwaskom/seaborn-data) by name; It's for testing. You are getting the 404 error because there is no ucc dataset in the github repository.
df = sns.load_dataset("ucc")

# This is the command that actually creates the plot. You are referencing a variable 'ucc' that you have not declared and you would get an error if you had not already excepted from the prior 404.
ax = sns.lineplot(x="hours", y="viability", data=ucc)

У меня нет вашего набора данных, поэтому я не могу дать вам точный пример, однако, используя загруженный локально набор данных mpg, я могу дать вам хотя бы работающий пример того, что, как я полагаю, вы пытаетесь выполнить sh.

import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

df = pd.read_csv('mpg.csv')
ax = sns.lineplot(x=df['model_year'], y=df['mpg'])

Matplotlib Lineplot of MPG over Model Year

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