https://plot.ly/python/bar-charts/#bar-chart-with-line-plot
我想使用plotly和iPython创建一个带有线条图的条形图,如上例所示.另一方面,我希望条形图是一个水平堆积条形图,如下面的例子中使用plotly和iPython.我该怎么做呢?
https://plot.ly/python/bar-charts/#colored-bar-chart
y_saving_yes = [1, 2, 4, 6, 7, 7]
y_saving_no = [10, 10, 10, 10, 10, 10]
y_net_worth = [93453, 81666, 69889, 78381, 141395, 92969]
x_saving = ['Premium', 'Spot Shadow', 'Slow Motion', 'Highlight Music','Extra Text', 'Top Play']
x_net_worth = ['Premium', 'Spot Shadow', 'Slow Motion', 'Highlight Music','Extra Text', 'Top Play']
trace1 = Bar(
x=y_saving,
y=x_saving,
marker=Marker(
color='rgba(50, 171, 96, 0.6)',
line=Line(
color='rgba(50, 171, 96, 1.0)',
width=1,
),
),
name='Highlight Properties',
orientation='h',
)
trace2 = Bar(
x=y_saving,
y=x_saving,
marker=Marker(
color='rgba(50, …Run Code Online (Sandbox Code Playgroud) 自从升级到IPython版本3(我有3.1.0)以来,每次使用该%timeit命令时,它都会打印出"最慢的运行时间比最快的时间长[数倍].这可能意味着在打印之前正在缓存中间结果"时间结果.即使是非常简单的操作也会发生这种 例如:
In [4]: x = 5
In [5]: %timeit x
The slowest run took 53.99 times longer than the fastest. This could mean that an intermediate result is being cached
100000000 loops, best of 3: 19.8 ns per loop
Run Code Online (Sandbox Code Playgroud)
和:
In [17]: %timeit 22 + 1
The slowest run took 106.15 times longer than the fastest. This could mean that an intermediate result is being cached
100000000 loops, best of 3: 12.2 ns per loop
Run Code Online (Sandbox Code Playgroud)
只有少数情况我可以让它不会发生,例如:
In …Run Code Online (Sandbox Code Playgroud) 我在远程ubuntu和本地osx上安装了两个iPython笔记本.当我尝试输出pandas数据帧时,我得到了不同的输出.查看截图.
我想在jupyter中使用ubuntu上的漂亮表格.
我该怎么办?我经常搜索,但一无所获.
我正在寻找一种(可能是创造性的)方式将文本放在jupyter笔记本中的图形旁边.我们的想法是对图表进行详细描述,而不是通常的笔记本垂直流程.
有任何想法吗?
Python(IPython-Jupyter笔记本)中是否有接受生成器的绘图选项?
AFAIK matplotlib不支持这一点.我发现的唯一选项是plot.ly和他们的Streaming API,但我不想使用在线解决方案,因为我需要实时绘制大量数据.
我正在研究一个有趣的小项目,它根据分形生成绘制一颗行星.我的项目在标准PyOpenGL调用下工作,但为了使它更具交互性,我想在IPython Notebook上导出它.
我只使用一些三角形,在笛卡尔坐标系中.有没有办法,就像three.js的目的,在IPython笔记本中根据一些多边形绘制一个非常基本的3D场景?我看到了很多静态绘图库,但没有看起来像我正在寻找的东西.
PS:通过互动,我可以旋转场景,例如.
假设在IPython笔记本中创建了一个ipywidget,如下所示:
from ipywidgets import widgets
i = widgets.IntText()
Run Code Online (Sandbox Code Playgroud)
有没有办法从Javascript设置值?我怀疑我需要知道小部件的一些通讯ID。还是有更好的方法在Python中使用Javascript设置变量?
用例是我想将鼠标单击位置(通过Javascript获得)位置发送回Python。
我今天才第一次看到这个。这三点东西叫什么?它有什么用?我的猜测是要帮助提高可读性。这是我看到的示例:
g = """
... S -> NP VP
... PP -> P NP
... NP -> Det N | Det N PP | 'I'
... VP -> V NP | VP PP
... Det -> 'an' | 'my'
... N -> 'elephant' | 'pajamas'
... V -> 'shot'
... P -> 'in'
... """
Run Code Online (Sandbox Code Playgroud)
这是它的输出:
"\nS -> NP VP\nPP -> P NP\nNP -> Det N | Det N PP | 'I'\nVP -> V NP | VP PP\nDet -> 'an' …Run Code Online (Sandbox Code Playgroud) 我正在使用Ipython笔记本,pandas库和散景图库,我有一个生成网格图的功能.我正在尝试设置一些复选框,每个复选框对应于其中一个图,然后仅使用选中了相应复选框的图更新网格图.似乎没有太多支持ipywidgets libray.这是我到目前为止的尝试; 我不知道如何将我创建的复选框传递给我的函数来更新我的网格图,所以任何帮助都将非常感激.谢谢.
attributes = df.columns.tolist()
from ipywidgets import Checkbox, interact
from IPython.display import display
chk = [Checkbox(description=attributes[i]) for i in range(len(attributes))]
#this displays the checkboxes I created correctly
display(*chk)
#update plot takes in the names of the columns to be displayed and returns
#a gridplot containing all corresponding plots
#not sure about the part below though
interact(updatePlot,args=chk)
Run Code Online (Sandbox Code Playgroud) 我最近尝试在我的几个类上实现"传递",以允许使用该__getattr__方法调用类的特定属性上的方法.这已经在ipython中破坏了(类型)自动完成,我很想知道为什么.第一:
class MyClass(object):
def __init__():
#create an instance of class ClassProperty
self.class_property = ClassProperty()
def __getattr__(self, item):
#pass through calls to non-existent methods, print first
print item
return getattr(self.class_property,item)
Run Code Online (Sandbox Code Playgroud)
当创建这个类的一个实例,然后试图制表完成在IPython中(0.12.1),似乎几个函数被调用,包括__methods__,trait_names和_getAttributeNames.
In [1]: my_class = MyClass()
In [2]: my_class.not_in_my_class<tab>
__methods__
trait_names
_getAttributeNames
Run Code Online (Sandbox Code Playgroud)
我很想知道发生了什么.
谢谢,
PS我知道这样做是非常不透明的,而且是暂时的.不过,我很好奇.
UPDATE
基于我从下面接受的答案中学到的东西,我已经能够成功地"通过"自动完成,以便ClassProperty现在存在于自动完成实例中的方法MyClass.成功通过所需的是对该__dir__方法的更新
class MyClass(object):
def __init__():
#create an instance of class ClassProperty
self.class_property = ClassProperty()
def __getattr__(self, item):
#pass through calls to …Run Code Online (Sandbox Code Playgroud)