小编Dre*_*met的帖子

seaborn color_palette as matplotlib colormap

Seaborn提供了一个名为color_palette的功能,可以让您轻松地为绘图创建新的color_palettes.

colors = ["#67E568","#257F27","#08420D","#FFF000","#FFB62B","#E56124","#E53E30","#7F2353","#F911FF","#9F8CA6"]

color_palette = sns.color_palette(colors)
Run Code Online (Sandbox Code Playgroud)

我想将color_palette转换为cmap,我可以在matplotlib中使用,但我不知道如何做到这一点.

可悲的是,像"cubehelix_palette","light_palette"这样的函数,......有一个"as_cmap"参数.不幸的是,"color_palette"没有.

python plot matplotlib seaborn

40
推荐指数
4
解决办法
3万
查看次数

如何为散景网格图设置默认/活动工具?

如果想要定义散景图的活动(默认)工具,可以通过将“active_drag”、“active_inspect”等参数传递给图形实例来设置,如此处所述

我尚未成功为网格图设置标准活动工具,其中所有单个图共享一个工具栏。这是我的代码的相关部分:

    tools = [
            PanTool(),
            BoxZoomTool(),
            WheelZoomTool(),
            UndoTool(),
            RedoTool(),
            ResetTool(),
            SaveTool(),
            HoverTool(tooltips=[
                ("Value", "$y")
                ])
            ]

    x_axes_range = Range1d(self.data.index[0], self.data.index[-1])

    for plot_type, plot_settings in pcfg.plot_types[self.name].items():

        plots.append(figure(x_axis_type="datetime", title=plot_type, plot_height = 400, x_range = x_axes_range, 
                            tools = tools, active_drag = None, active_inspect = None, active_scroll = None, active_tap = None))
    ...

    plots[plot_counter].line(self.data.index, self.data[parameter], color=parameter_settings[1], legend=parameter_settings[0])

...

gp = gridplot(plots, ncols = 1, sizing_mode = "scale_width")

script, div = components(gp)
Run Code Online (Sandbox Code Playgroud)

因此,发生的情况是,“BoxZoomTool()”在我显示它的网站上被选为活动工具,尽管我在图形初始化中将活动工具设置为 None,但可用工具是我传递给 inits 的工具figure()

我确实在这里看到了“toolbar_option” ,但我不知道如何使用该参数更改活动工具。

python plot python-3.x bokeh

6
推荐指数
1
解决办法
7959
查看次数

如何为pandas数据框中的多个非现有列分配值?

所以我想要做的是将列添加到数据帧并用单个值填充它们(分别为所有行).

import pandas as pd
import numpy as np

df = pd.DataFrame(np.array([[1,2],[3,4]]), columns = ["A","B"])
arr = np.array([7,8])

# this is what I would like to do
df[["C","D"]] = arr

# and this is what I want to achieve
#    A  B  C  D
# 0  1  2  7  8
# 1  3  4  7  8
# but it yields an "KeyError" sadly
# KeyError: "['C' 'D'] not in index"
Run Code Online (Sandbox Code Playgroud)

如果我只是一次添加一个列,我确实知道了assign-functions以及如何解决这个问题.我只是想知道是否有一个干净而简单的方法来处理多个新列,因为我无法找到它.

python numpy pandas

5
推荐指数
1
解决办法
745
查看次数

标签 统计

python ×3

plot ×2

bokeh ×1

matplotlib ×1

numpy ×1

pandas ×1

python-3.x ×1

seaborn ×1