以下示例返回错误。似乎不支持在Python的ggplot中使用离散(非连续)缩放比例的x轴吗?
import pandas as pd
import ggplot
df = pd.DataFrame.from_dict({'a':['a','b','c'],
'percentage':[.1,.2,.3]})
p = ggplot.ggplot(data=df,
aesthetics=ggplot.aes(x='a',
y='percentage'))\
+ ggplot.geom_point()
print(p)
如上所述,这将返回:
Traceback (most recent call last):
File "/Users/me/Library/Preferences/PyCharm2016.1/scratches/scratch_1.py", line 30, in <module>
print(p)
File "/Users/me/lib/python3.5/site-packages/ggplot/ggplot.py", line 116, in __repr__
self.make()
File "/Users/me/lib/python3.5/site-packages/ggplot/ggplot.py", line 627, in make
layer.plot(ax, facetgroup, self._aes, **kwargs)
File "/Users/me/lib/python3.5/site-packages/ggplot/geoms/geom_point.py", line 60, in plot
ax.scatter(x, y, **params)
File "/Users/me/lib/python3.5/site-packages/matplotlib/__init__.py", line 1819, in inner
return func(ax, *args, **kwargs)
File "/Users/me/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 3838, in scatter
x, y, s, c = cbook.delete_masked_points(x, y, s, c)
File "/Users/me/lib/python3.5/site-packages/matplotlib/cbook.py", line 1848, in delete_masked_points
raise ValueError("First argument must be a sequence")
ValueError: First argument must be a sequence
在离散比例上使用ggplot
散点图的任何变通方法?
答案 0 :(得分:1)
一种选择是生成连续系列,并使用原始变量作为标签。但这似乎是一个痛苦的解决方法。
while (!q.empty()){
System.out.println(q.Dequeue());
答案 1 :(得分:0)
我在尝试绘制数据帧的2列时遇到了同样的错误。我正在从csv文件中读取数据并将其转换为数据帧。
readdata=csv.reader(open(filename),delimiter="\t")
df= pd.DataFrame(data, columns=header)
df.columns=["pulseVoltage","dutVoltage","dutCurrent","leakageCurrent"]
print (df.dtypes)
当我检查数据类型时,由于某种原因,它们被显示为对象而不是我期望的浮动(我是一个新手,这可能是我不知道的琐碎知识)。因此,我继续并将列显式转换为数据类型float。
df["dutVoltage"]=df["dutVoltage"].astype("float")
df["dutCurrent"]=df["dutCurrent"].astype("float")
现在我可以使用ggplot绘制数据而不会出现任何错误。
print ggplot(df, aes('dutVoltage','dutCurrent'))+ \
geom_point()