ModuleNotFoundError.没有名为'plotly.validators.scatter._line'的模块。没有名为 "plotly.validators.scatter._line "的模块。

问题描述 投票:0回答:1

图形图像 我想用Plotly函数做一个线图,我已经安装了新的chart_studio包。我能够使用这段代码制作一个图形。

a = np.linspace(start=0, stop=36, num=36)

np.random.seed(25)

b = np.random.uniform(low=0.0, high=1.0, size=36)

trace = go.Scatter(x=a, y=b)

data = [trace]

py.iplot(data, filename='basic-line-chart')

这段代码可以工作,并生成一个线图 当我尝试使用Pandas导入csv文件,并使用这段代码导入线图时,我得到一个错误。

address = "C:\\Users\\Mattbot\\Documents\\Python Data Science\\Ex_Files_Python_Data_Science_EssT_Pt_1\\Exercise Files\\Data\\mtcars.csv"

cars = pd.read_csv(address)
cars.columns = ['car_names','mpg','cyl','disp', 'hp', 'drat', 'wt', 'qsec', 'vs', 'am', 'gear', 'carb']

df = cars[['cyl', 'wt','mpg']]

layout = dict(title='Chart from Pandas DataFrame', xaxis= dict(title='x-axis'), yaxis= dict(title='y-axis'))

df.iplot(filename='cf-simple-line-chart', layout=layout)

我在下面引用了整个错误,如果这有帮助的话。先为我对Plotly和python的经验不足表示抱歉。我试着在plotly论坛上问过这个问题,但没有用。任何建议都将是非常感激的。

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-22-62304e9e67f2> in <module>
      8 layout = dict(title='Chart from Pandas DataFrame', xaxis= dict(title='x-axis'), yaxis= dict(title='y-axis'))
      9 
---> 10 df.iplot(filename='cf-simple-line-chart', layout=layout)

C:\ProgramData\Anaconda3\lib\site-packages\cufflinks\plotlytools.py in _iplot(self, kind, data, layout, filename, sharing, title, xTitle, yTitle, zTitle, theme, colors, colorscale, fill, width, dash, mode, interpolation, symbol, size, barmode, sortbars, bargap, bargroupgap, bins, histnorm, histfunc, orientation, boxpoints, annotations, keys, bestfit, bestfit_colors, mean, mean_colors, categories, x, y, z, text, gridcolor, zerolinecolor, margin, labels, values, secondary_y, secondary_y_title, subplots, shape, error_x, error_y, error_type, locations, lon, lat, asFrame, asDates, asFigure, asImage, dimensions, asPlot, asUrl, online, **kwargs)
    839                 data=df.to_iplot(colors=colors,colorscale=colorscale,kind=kind,interpolation=interpolation,fill=fill,width=width,dash=dash,sortbars=sortbars,keys=keys,
    840                                                 bestfit=bestfit,bestfit_colors=bestfit_colors,mean=mean,mean_colors=mean_colors,asDates=asDates,mode=mode,symbol=symbol,size=size,
--> 841                         text=text,**kwargs)     
    842                                 trace_kw=check_kwargs(kwargs,TRACE_KWARGS)
    843                                 for trace in data:

C:\ProgramData\Anaconda3\lib\site-packages\cufflinks\plotlytools.py in _to_iplot(self, colors, colorscale, kind, mode, interpolation, symbol, size, fill, width, dash, sortbars, keys, bestfit, bestfit_colors, opacity, mean, mean_colors, asDates, asTimestamp, text, **kwargs)
    159                 lines_plotly=[Bar(lines[key]).to_plotly_json() for key in keys]
    160         else:
--> 161                 lines_plotly=[Scatter(lines[key]).to_plotly_json() for key in keys]
    162         for trace in lines_plotly:
    163                 if isinstance(trace['name'],pd.Timestamp):

C:\ProgramData\Anaconda3\lib\site-packages\cufflinks\plotlytools.py in <listcomp>(.0)
    159                 lines_plotly=[Bar(lines[key]).to_plotly_json() for key in keys]
    160         else:
--> 161                 lines_plotly=[Scatter(lines[key]).to_plotly_json() for key in keys]
    162         for trace in lines_plotly:
    163                 if isinstance(trace['name'],pd.Timestamp):

C:\ProgramData\Anaconda3\lib\site-packages\plotly\graph_objs\_scatter.py in __init__(self, arg, cliponaxis, connectgaps, customdata, customdatasrc, dx, dy, error_x, error_y, fill, fillcolor, groupnorm, hoverinfo, hoverinfosrc, hoverlabel, hoveron, hovertemplate, hovertemplatesrc, hovertext, hovertextsrc, ids, idssrc, legendgroup, line, marker, meta, metasrc, mode, name, opacity, orientation, r, rsrc, selected, selectedpoints, showlegend, stackgaps, stackgroup, stream, t, text, textfont, textposition, textpositionsrc, textsrc, texttemplate, texttemplatesrc, tsrc, uid, uirevision, unselected, visible, x, x0, xaxis, xcalendar, xsrc, y, y0, yaxis, ycalendar, ysrc, **kwargs)

C:\ProgramData\Anaconda3\lib\site-packages\plotly\basedatatypes.py in __setitem__(self, prop, value)

C:\ProgramData\Anaconda3\lib\site-packages\plotly\basedatatypes.py in _get_validator(self, prop)

C:\ProgramData\Anaconda3\lib\site-packages\plotly\validator_cache.py in get_validator(parent_path, prop_name)

C:\ProgramData\Anaconda3\lib\site-packages\_plotly_utils\importers.py in __getattr__(import_name)

C:\ProgramData\Anaconda3\lib\importlib\__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load(name, import_)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'plotly.validators.scatter._line'
python plotly
1个回答
0
投票

根据你添加的情节,在我看来你要找的是这样的东西

import pandas as pd
import plotly.express as px

url = "https://gist.githubusercontent.com/seankross/a412dfbd88b3db70b74b/raw/5f23f993cd87c283ce766e7ac6b329ee7cc2e1d1/mtcars.csv"
df = pd.read_csv(url)

# these are the columns you want to plot
cols = ['cyl', 'wt','mpg']
# all columns must have the same dtype
# if you want to use plotly.express
df[cols] = df[cols].astype("float")

px.line(df, x=df["model"], y=cols)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.