seaborn学习笔记(三):直方图、条形图、条带图

2023-11-05

1 直方图与条形图

在过去很长一段时间,我一直分不清直方图和条形图,或者说一直认为两者是一样的,直到看到histplot()和barplot()两个绘图方法,前者是绘制直方图,后者是绘制条形图。通过仔细对比两者各项功能后,我得出结论,两者十分相似,但有些许不同:直方图侧重于统计数据在数轴上各个位置的分布情况,统计的对象往往是连续型数值数据的,根据数值的大小分区间进行分组统计,例如有100个学生的身高,需要统计100个学生在各个身高段的分布情况;条形图不同,条形图分组往往是针对离散型数据或者说定性的分类数据,例如对比男生的平均身高和女生的平均身高。不知道我这么理解对不对,欢迎留言讨论。

2 histplot():直方图

主要参数如下:

  • data:绘图数据,可以是pandas.DataFrame,numpy.ndarray或者字典等
  • x,y:指定的x轴, y轴数据,可以是向量或者字符串,当是字符串时,一定是data中的一个key
  • hue:可以是向量(pandas中的一列,或者是list),也可以是字符串(data中的一个key),seaborn将根据这一列设置不同颜色
  • weights: 数据加权的权重
  • stat: 柱形的统计方式

    1)count:统计每个区间的值的个数

    2)frequency:区间内取值个数除以区间宽度

    3)probability或proportion:进行标准化使条形高度总和为1

    4)percent:标准化使条形总高度为100

    5)使条形总面积为1

  • bins: 字符型、整型、向量都可以,可以是引用规则的名称、箱子的数量或箱子的分段或者分箱规则名称,规则名称见下方示例
  • binwidth: 条形宽度
  • binrange: 条形边缘的最大值或最小值
  • discrete: 如果为True,则默认为binwidth=1,并绘制条形图,使其位于相应数据点的中心。这避免了在使用离散(整数)数据时可能出现的“间隙”。
  • cumulative: 布尔型,是否逐个累加每个条形高度进行绘图
  • multiple: 直接看下文效果吧
  • element: 直接看下文效果吧
  • fill: 条形内部是否填充颜色
  • shrink: 缩小条形的宽度
  • kde: 是否生成核密度曲线
  • color: 设置条形颜色
  • legend: 是否显示图例
  • ax: 绘图的坐标轴实例
In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

In [2]:
penguins = sns.load_dataset('penguins',data_home='.')

In [3]:
penguins.head(2)

Out[3]:
  species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g sex
0 Adelie Torgersen 39.1 18.7 181.0 3750.0 Male
1 Adelie Torgersen 39.5 17.4 186.0 3800.0 Female

2.1 为图像设置标题

histplot()方法返回值为matplotlib.axes._subplots.AxesSubplot类实例,通过实例的set_title()方法可以为图像添加标题:

In [4]:
pic = sns.histplot(penguins, x="flipper_length_mm")
pic.set_title('flipper_length_mm')

Out[4]:
Text(0.5, 1.0, 'flipper_length_mm')

2.2 ax:自定义绘图坐标系

在不传递ax参数时,seaborn会自行创建坐标系进行绘图,我们也可以自己创建坐标系,通过ax参数传递,这样做的好处是可以灵活绘制多个子图:

In [5]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[0])
pic = sns.histplot(penguins, x="body_mass_g", ax=ax[1])

另外,在histplot()方法中,没有提供太多关于坐标轴设置的参数,难以对坐标轴进行个性化定制,如果在绘图前,先创建好坐标轴,即可完成对坐标轴的设置(关于坐标轴的创建和设置,请参考Matplotlib数据可视化(2):三大容器对象与常用设置

In [6]:
ax=plt.axes((0.1, 0.1, 0.8, 0.7), facecolor='green')
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax)

2.3 x, y:传递数据,控制图形方向

x, y参数不能同时传递,当传递x时,x轴为数据取值范围,y轴为统计次数;当传递y值时,y轴为数据取值范围,x轴为统计次数:

In [7]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[0])
pic.set_title('x')
pic = sns.histplot(penguins, y="flipper_length_mm", ax=ax[1])
pic.set_title('y')

Out[7]:
Text(0.5, 1.0, 'y')

2.4 stat:y轴显示数据的方式

In [8]:
fig, ax =plt.subplots(1,5,constrained_layout=True, figsize=(15, 3))
_ = sns.histplot(penguins, x="flipper_length_mm", stat="count", ax=ax[0])      # count, 也是默认值
_ = sns.histplot(penguins, x="flipper_length_mm", stat="frequency", ax=ax[1])  # frequency 
_ = sns.histplot(penguins, x="flipper_length_mm", stat="probability", ax=ax[2])# probability
_ = sns.histplot(penguins, x="flipper_length_mm", stat="percent", ax=ax[3])    # percent
_ = sns.histplot(penguins, x="flipper_length_mm", stat="density", ax=ax[4])    # density

2.5 bins:指定分箱方式

指定分箱个数或者每个条形区间进行绘图:

In [9]:
fig, ax =plt.subplots(1,3,constrained_layout=True, figsize=(12, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[0], bins=5)
pic.set_title('bins=5')
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[1], bins=10)
pic.set_title('bins=10')
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[2], bins=[150, 175, 200, 225, 250])
pic.set_title('bins=[150, 175, 200, 225, 250]')

Out[9]:
Text(0.5, 1.0, 'bins=[150, 175, 200, 225, 250]')

也可以指定分箱的规则:

In [10]:
fig, ax =plt.subplots(2,4,constrained_layout=True, figsize=(15, 6))
pic = sns.histplot(penguins, x="flipper_length_mm", bins="auto", ax=ax[0][0])      # count, 也是默认值
pic.set_title('auto')
pic = sns.histplot(penguins, x="flipper_length_mm", bins="fd", ax=ax[0][1])  # frequency 
pic.set_title('fd')
pic = sns.histplot(penguins, x="flipper_length_mm", bins="doane", ax=ax[0][2])# probability
pic.set_title('doane')
pic = sns.histplot(penguins, x="flipper_length_mm", bins="scott", ax=ax[0][3])    # percent
pic.set_title('scott')
pic = sns.histplot(penguins, x="flipper_length_mm", bins="stone", ax=ax[1][0])      # count, 也是默认值
pic.set_title('stone')
pic = sns.histplot(penguins, x="flipper_length_mm", bins="rice", ax=ax[1][1])  # frequency 
pic.set_title('rice')
pic = sns.histplot(penguins, x="flipper_length_mm", bins="sturges", ax=ax[1][2])# probability
pic.set_title('sturges')
pic = sns.histplot(penguins, x="flipper_length_mm", bins="sqrt", ax=ax[1][3])    # percent
pic.set_title('sqrt')

D:\ProgramData\Anaconda3\envs\machine_learning\lib\site-packages\numpy\lib\histograms.py:669: RuntimeWarning: The number of bins estimated may be suboptimal.
  bin_edges, _ = _get_bin_edges(a, bins, range, weights)

Out[10]:
Text(0.5, 1.0, 'sqrt')

2.6 binwidth:设置柱形宽度

In [11]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
_ = sns.histplot(penguins, x="flipper_length_mm", ax=ax[0], binwidth=1)
_ = sns.histplot(penguins, x="flipper_length_mm", ax=ax[1], binwidth=3)

2.7 cumulative:累积每个条形高度进行绘图

In [12]:
sns.histplot(penguins, x="flipper_length_mm", cumulative=True)

Out[12]:
<AxesSubplot:xlabel='flipper_length_mm', ylabel='Count'>
In [13]:
sns.histplot(penguins, x="flipper_length_mm", multiple="layer")

Out[13]:
<AxesSubplot:xlabel='flipper_length_mm', ylabel='Count'>

2.8 hue:颜色区分条形组成

In [14]:
_ = sns.histplot(penguins, x="flipper_length_mm", hue="species")

2.9 element

In [15]:
fig, ax =plt.subplots(1,3,constrained_layout=True, figsize=(12, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", hue="species", ax=ax[0], element="bars")
pic.set_title('element="bars"')
pic = sns.histplot(penguins, x="flipper_length_mm", hue="species", ax=ax[1], element="step")
pic.set_title('element="step')
pic = sns.histplot(penguins, x="flipper_length_mm", hue="species", ax=ax[2], element="poly")
pic.set_title('element="poly"')

Out[15]:
Text(0.5, 1.0, 'element="poly"')

2.10 multiple

In [16]:
fig, ax =plt.subplots(1,4,constrained_layout=True, figsize=(16, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", hue="species", ax=ax[0], multiple="layer")
pic.set_title('multiple="layer"')
pic = sns.histplot(penguins, x="flipper_length_mm", hue="species", ax=ax[1], multiple="dodge")
pic.set_title('multiple="dodge')
pic = sns.histplot(penguins, x="flipper_length_mm", hue="species", ax=ax[2], multiple="stack")
pic.set_title('multiple="stack"')
pic = sns.histplot(penguins, x="flipper_length_mm", hue="species", ax=ax[3], multiple="fill")
pic.set_title('multiple="fill"')

Out[16]:
Text(0.5, 1.0, 'multiple="fill"')

2.11 kde:是否生成核密度曲线

In [17]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[0], kde=False)  # 默认值,不生成核密度曲线
pic.set_title('kde=False')
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[1], kde=True)  # 值为True,显示核密度曲线
pic.set_title('kde=True')

Out[17]:
Text(0.5, 1.0, 'kde=True')

2.12 color:设置条形颜色

In [18]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[0], color="#FFC0CB")  # 可以使16进制颜色
pic.set_title('color="#FFC0CB"')
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[1], color="orange")  # 也可以是 英文颜色字符串
pic.set_title('color="orange"')

Out[18]:
Text(0.5, 1.0, 'color="orange"')
In [19]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[0], color="#FFC0CB")  # 可以使16进制颜色
pic.set_title('color="#FFC0CB"')
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[1], color="orange")  # 也可以是 英文颜色字符串
pic.set_title('color="orange"')

Out[19]:
Text(0.5, 1.0, 'color="orange"')

2.13 fill:条形内部是否填充颜色

In [20]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", hue='sex', ax=ax[0], fill=False)
pic.set_title('fill=False')
pic = sns.histplot(penguins, x="flipper_length_mm", hue='sex', ax=ax[1], fill=True)
pic.set_title('fill=True')

Out[20]:
Text(0.5, 1.0, 'fill=True')

2.14 legend:是否显示图例

In [21]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", hue="sex", ax=ax[0], legend=False)
pic.set_title('legend=False')
pic = sns.histplot(penguins, x="flipper_length_mm", hue="sex", ax=ax[1], legend=True)
pic.set_title('legend=True')

Out[21]:
Text(0.5, 1.0, 'legend=True')

2.15 shrink:缩小条形

shrink参数可以缩小条形增大条形之间的间隔:

In [22]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[0], shrink=0.5)
pic.set_title('shrink=0.5')
# pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[1], bins=10)
pic = sns.histplot(penguins, x="flipper_length_mm", ax=ax[1], shrink=0.8)
pic.set_title('shrink=0.8')

Out[22]:
Text(0.5, 1.0, 'shrink=0.8')

2.16 edgecolor:指定边框颜色

In [47]:
_ = sns.histplot(penguins, x="flipper_length_mm", edgecolor="red")

3 barplot():条形图

  • x,y:指定的x轴, y轴数据,可以是向量或者字符串,当是字符串时,一定是data中的一个key
  • hue:可以是向量(pandas中的一列,或者是list),也可以是字符串(data中的一个key),seaborn将根据这一列设置不同颜色
  • data:绘图数据,可以是pandas.DataFrame,numpy.ndarray或者字典等
  • order:包含所有分组属性的列表,用于指定条形顺序,注意如果某个分组不在order中,该分组将不会显示
  • hue_order:字符串组成的list,设置hue后设置各颜色顺序
  • estimator:可调用对象,分组统计的方式,或者说条形图长度所表示的意义,可以使以下值:

    • len:调用内置的len方法统计数据总长

    • np.mean:表示统计各分组平均值,这也是默认的方式

    • np.sum:表示统计各分组总和

    • np.ptp:极差

    • np.median:统计中位数

    • np.std:标准差

    • np.var:方差

  • ci:float或者"sd"或None,在估计值附近绘制置信区间的大小,如果是"sd",则跳过bootstrapping并绘制观察的标准差,如果为None,则不执行bootstrapping,并且不绘制错误条。
  • orient:当x,y都是离散型或者数值型数据时,通过orient可设置图像方向
  • color:为所有条形设置统一颜色
  • palette:颜色面板,比color参数功能更加强大,更加个性化地设置条形的颜色
  • errcolor:错误带的颜色
  • errwidth:错误带的宽度
  • capsize:错误带“帽子”宽度
  • ax:自定义坐标系
In [23]:
tips = sns.load_dataset("tips")

In [24]:
tips.head(2)

Out[24]:
  total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3

3.1 x, y:传递数据,控制图形方向

x, y为绘图时指定的x轴和y轴数据,x、y如果有一个是离散型数据(或者说定性数据、分类数据),另一个是连续性数值数据,seaborn将会根据其中的离散型数据对另一个连续性数据进行分组统计,同时也决定绘图的方向。如果两个都是数值型数据,可以通过orient指定方向。

In [25]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.barplot(x="total_bill", y="day", data=tips, ax=ax[0])
pic.set_title('x="total_bill", y="day"')
pic = sns.barplot(x="day", y="total_bill", data=tips, ax=ax[1])
pic.set_title('x="day", y="total_bill"')

Out[25]:
Text(0.5, 1.0, 'x="day", y="total_bill"')

3.2 estimator:分组统计方式

In [26]:
fig, ax =plt.subplots(1,3,constrained_layout=True, figsize=(12, 3))
pic = sns.barplot(x="day", y="total_bill", data=tips, ax=ax[0], estimator=np.mean)
pic.set_title('estimator=np.mean')
pic = sns.barplot(x="day", y="total_bill", data=tips, ax=ax[1], estimator=np.std)
pic.set_title('np.std')
pic = sns.barplot(x="day", y="total_bill", data=tips, ax=ax[2], estimator=len)  # 内置方法len统计总次数
pic.set_title('len')

Out[26]:
Text(0.5, 1.0, 'len')

3.3 order:指定条形顺序

In [27]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.barplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('default order')
pic = sns.barplot(x="day", y="total_bill", data=tips, order=['Sun', 'Sat', 'Thur', 'Fri'], ax=ax[1])
pic.set_title('"Sun", "Sat", "Thur", "Fri"')

Out[27]:
Text(0.5, 1.0, '"Sun", "Sat", "Thur", "Fri"')

3.4 hue:根据字段设置不同颜色

In [28]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.barplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('no hue')
pic = sns.barplot(x="day", y="total_bill", data=tips, ax=ax[1], hue="sex")
pic.set_title('hue="sex"')

Out[28]:
Text(0.5, 1.0, 'hue="sex"')

3.5 color,saturation:设置条形颜色和饱和度

注意,color只能一次性设置所有条形统一的颜色,如果要为条形设置不同颜色,要通过palette参数:

In [29]:
ax = sns.barplot(x="day", y="total_bill", data=tips, color="red")

In [30]:
ax = sns.barplot(x="day", y="total_bill", data=tips, color="red",saturation=0.5 )

3.6 errcolor:错误带的颜色

In [31]:
ax = sns.barplot(x="day", y="total_bill", data=tips, errcolor="red")

3.7 errwidth:错误带的宽度

In [32]:
ax = sns.barplot(x="day", y="total_bill", data=tips, errwidth=8)

3.8 capsize:错误带“帽子”宽度

In [33]:
ax = sns.barplot(x="day", y="total_bill", data=tips, capsize=.2)

4 stripplot():条带图

条带图是是一种比较少见的图表,综合了散点图和直方图/条形图的图形特征和优势,其表达的含义又与箱型图十分类似。stripplot()参数如下:

  • x,y:指定的x轴, y轴数据,可以是向量或者字符串,当是字符串时,一定是data中的一个key
  • hue:可以是向量(pandas中的一列,或者是list),也可以是字符串(data中的一个key),seaborn将根据这一列设置不同颜色
  • data:绘图数据,可以是pandas.DataFrame,numpy.ndarray或者字典等
  • order:包含所有分组属性的列表,用于指定条形顺序,注意如果某个分组不在order中,该分组将不会显示
  • hue_order:字符串组成的list,设置hue后设置各颜色顺序
  • jitter:抖动量,当数据很多时,增加抖动量,使散点不至于聚成一团
  • dodge:在hue基础上,将不同颜色的散点分开
  • orient:当x,y都是离散型或者数值型数据时,通过orient可设置图像方向
  • color:统一设置所有散点的颜色
  • palette:颜色面板
  • size:散点的大小
  • edgecolor:散点的边框颜色
  • linewidth:散点边框宽度
  • ax:自定义坐标系

4.1 x, y:传递数据,控制图形方向

x, y为绘图时指定的x轴和y轴数据,x、y如果有一个是离散型数据(或者说定性数据、分类数据),另一个是连续性数值数据,seaborn将会根据其中的离散型数据对另一个连续性数据进行绘制其在另一条数轴上的分布。

In [34]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[0])
pic.set_title('x="day", y="total_bill"')
pic = sns.stripplot(x="total_bill", y="day", data=tips, ax=ax[1])
pic.set_title('x="total_bill", y="day"')

Out[34]:
Text(0.5, 1.0, 'x="total_bill", y="day"')

4.2 jitter:抖动量

In [35]:
fig, ax =plt.subplots(1,3,constrained_layout=True, figsize=(12, 3))
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[0], )
pic.set_title('no jitter')
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[1], jitter=0.05)
pic.set_title('jitter=0.05')
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[2], jitter=0.3)
pic.set_title('jitter=0.3')

Out[35]:
Text(0.5, 1.0, 'jitter=0.3')

4.3 color:统一设置散点的颜色

In [36]:
sns.stripplot(x="day", y="total_bill", data=tips, color='red')

Out[36]:
<AxesSubplot:xlabel='day', ylabel='total_bill'>

4.4 size:散点的大小

In [37]:
fig, ax =plt.subplots(1,3,constrained_layout=True, figsize=(12, 3))
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[0], )
pic.set_title('no jitter')
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[1], size=2)
pic.set_title('size=2')
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[2], size=10)
pic.set_title('size=10')

Out[37]:
Text(0.5, 1.0, 'size=10')

4.5 linewidth与edgecolor:散点边框宽度、颜色

In [38]:
fig, ax =plt.subplots(1,4,constrained_layout=True, figsize=(16, 3))
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[0], )
pic.set_title('no linewidth')
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[1], linewidth=1)
pic.set_title('linewidth=1')
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[2], linewidth=2)
pic.set_title('linewidth=2')
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[3], linewidth=1, edgecolor="yellow")
pic.set_title('linewidth=1, edgecolor="red"')

Out[38]:
Text(0.5, 1.0, 'linewidth=1, edgecolor="red"')

4.6 hue与dodge:根据指定指定绘制散点颜色

hue和dodge常常需要一起配合使用,hue只是根据指定字段绘制不同颜色的散点,进一步地,dodge可以将不同颜色的散点分开

In [39]:
fig, ax =plt.subplots(1,2,constrained_layout=True, figsize=(8, 3))
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[0], hue="smoker")
pic.set_title('hue="smoker"')
pic = sns.stripplot(x="day", y="total_bill", data=tips, ax=ax[1], hue="smoker", dodge=True)
pic.set_title('hue="smoker", dodge=True')

Out[39]:
Text(0.5, 1.0, 'hue="smoker", dodge=True')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

seaborn学习笔记(三):直方图、条形图、条带图 的相关文章

  • 加快写入多个图像 TIFF 的速度?

    我正在尝试将图像堆栈写入 TIFF 文件 图像大小为 256 256 像素 每个堆栈包含 1000 张图像 编写其中一个文件大约需要 4 分钟 所以我的代码很可能有问题 这就是我正在做的 void Tiff WriterSplit floa
  • Attunity 连接器未显示在 VS 2017、SQL Server 2017 的 SSIS 中

    我看过 VS 2015 的这篇文章 但没有看过 VS 2017 的文章 我已经测试了 Visual Studio 2017 SSDT Enterprise 和 Professional 以及 SQL Server 2017 我遵循了该帖子h
  • 使用facet_grid从ggplot中提取单个图

    我想使用 ggplot 和生成一些图facet grid并将绘图保存为对象 我的问题是我还想将每个子组 即每个方面 单独保存为一个对象 我现在的问题是你是否可以从中提取一个方面facet grid并将其保存为对象 这是一些简单的代码 lib
  • 更改 ggplot 条形图填充颜色

    有了这个数据 df lt data frame value c 20 50 90 group c 1 2 3 我可以得到一个条形图 df gt ggplot aes x group y value fill value geom col c
  • 如何返回以列名作为第一行的 T-SQL 查询

    我正在编写一个 SSIS 包来将数据从 SQL Server 2012 数据库输出到 CSV为客户归档 要求是第一行是列名称 下面是我为数据流任务中的源编写的查询 问题是 它总是将列名返回为最后一行 而不是第一行 为什么 我该如何实现这一目
  • 使用facet时ggplot2控制每行的面板数量?

    Is it possible to control the number of panels per row in a ggplot I can only get an equal number of panels on each row
  • 创建后修改 ggplot 对象

    有没有首选的修改方式ggplot创建后的对象 例如 我建议我的学生将 r 对象与 pdf 文件一起保存以供以后更改 library ggplot2 graph lt ggplot mtcars aes x mpg y qsec fill c
  • 如何缩放(标准化)每列内的 ggplot2 stat_bin2d 值(按 X 轴)

    我有一个 ggplot stat bin2d 热图 library ggplot2 value lt rep 1 5 1000 df lt as data frame value df group lt rep 1 7 len 5000 d
  • 指定生存图的自定义时间点

    我正在努力使用以下方法创建生存 累积事件图ggsurvplot函数从survminer包裹 我想为我的绘图指定自定义时间点 但我不知道该怎么做 这xlim and break x by参数有点帮助 但它们创建了均匀间隔的时间点和比我想要的更
  • SSIS - 将参数传递给 ADO .NET 源查询

    我知道早些时候已经有人问过这个问题 大多数答案都不相关 谷歌了一下 显示解决办法是在 数据流任务 中配置表达式并设置查询 然而 在 ADO NET 源中 当我尝试预览输出时 我不断收到 Must declare the variable 它
  • 为“facet_wrap”中的每列创建边框和标题

    我想在每个方面周围放置带有标签和标题的黑色边框facet wrap 与此类似的东西 样本数据 library tidyverse mtcars gt mutate gear factor gear levels c 4 3 5 gt ggp
  • 我想在 64 位模式下运行我的视觉工作室

    我正在 NET 3 5 中编写 Web 服务 在此我必须访问 SharePoint 2010 数据 但 SharePoint 需要我的应用程序使用 64 位模式 Visual Studio 默认处于 32 位模式 如何以 64 位运行 Vi
  • 了解用于处理色边距的scale_fill_continuous_divergingx参数输入

    这个问题是我上一个问题的延续here https stackoverflow com questions 58718527 setting midpoint for continuous diverging color scale on a
  • 如何融合颜色和形状?

    当我有一个超过 6 个值的变量时 我的麻烦就开始了 因为这是 ggplot2 中 scale shape 函数的当前最大值 由于这个问题 我尝试使用另一个变量来解决这个问题 我只是将原始变量的长度包裹起来 这是我的示例代码 dataf lt
  • 如何将带有观察计数的标签添加到 stat_summary ggplot?

    我有一个数据集 例如 outcome lt c rnorm 500 45 10 rnorm 250 40 12 rnorm 150 38 7 rnorm 1000 35 10 rnorm 100 30 7 group lt c rep A
  • ggplot 图例标签内的希腊字母、符号和换行符

    我在尝试着 有换行符 自动或强制 对齐文本 左对齐或左右对齐 有希腊字母和百分号 在 gglot 图例标签内 我尝试了几种方法 但我似乎无法将我读到的所有技巧结合起来 我可以通过插入来换行 n进入标签 但这似乎不适用于希腊字母 不适用于图例
  • 如何使用 SSIS 将多个 Access 数据库导入到 SQL Server

    我有一个文件夹 其中包含 300 多个 Access 数据库 由我无法控制的程序编写 它们都有相同的结构 只是一张表 我正在将数据导入到 SQL Server 2005 中的表中 使用导入向导效果很好 但它一次只能用于一个 Access 数
  • 如何在 python 中读取 32 位 TIFF 图像?

    我想用 python 读取 32 位浮点图像文件来进行一些图像分析 我努力了 import matplotlib pyplot as plt im plt imread path to file tif 但是 这仅将数据读取为 8 位整数值
  • 手动设置scale_fill_distiller()的比例

    我正在尝试制作一系列图表进行比较 举例来说 我想使用iris数据集来制作这样的图 其中我已过滤以仅查看 setosa 物种 library ggplot2 library dplyr iris gt filter Species setos
  • 使用officer R导出时如何提高ggplots的分辨率

    我想将图表导出到 PPT 并使用Officer 包来实现相同的目的 但是 图表的默认分辨率较低 我想更改它 我目前正在使用以下电话 ph with gg p1 type chart res 1200 其中 p1 是 ggplot 对象 运行

随机推荐

  • 为什么程序员一定要会用Google和Stack Overflow?

    内容简介 前言 为什么用Google不用百度 为什么用Stack Overflow 小结 前言 下文中 谷歌统一用Google表示 作为程序员 用Google比用百度更节省时间 此话不假 在法国工作也有4年了 加上之前的两个6个月的实习 勉
  • angularjs中post请求进行跨域

    post请求进行跨域 angularjs内置封装了类ajax的网络服务 http 所以实现了依赖外部插件来完成完整的前后端分离方案 scope main getData function http method POST url http
  • Git基于已有分支创建新的分支,简单的git 命令

    准备工作 进入要创建git分支项目目录 打开git命令行 1 基于已有分支代码创建新的分支 git checkout b new branch name origin source branch 2 将代码推送到新创建的git分支上 git
  • Qt Creator使用内存泄漏检测工具Valgrind

    Qt Creator使用内存泄漏检测工具Valgrind 随着软件变得越来越复杂 内存泄漏和野指针问题已经成为程序员最头痛的问题之一 幸运的是 现代IDE提供了许多工具来帮助我们解决这些问题 在这篇文章中 我们将介绍如何在Qt Creato
  • 单价数量和总价的公式_小学六年超全的数学公式!家长们赶紧给孩子看过来……...

    小学数学基础知识整理 一到六年级 小学一年级 初步认识加减法 学会基础加减 小学二年级 完善加减法 表内乘法 学会应用题 基础几何图形 小学三年级 学会万以内加减法 长度单位和质量单位 倍数的认知 多位数乘一位数 时间量及单位 长方形和正方
  • 租赁OLED透明屏:打造独特商业体验的智慧选择

    近年来 OLED透明屏技术在商业领域中迅速崛起 其高透明度和卓越的图像质量为商家创造了全新的展示方式 租赁OLED透明屏作为一种智慧选择 不仅能提升品牌形象和吸引力 还能创造与众不同的视觉体验 对此 尼伽将和大家一起深入探讨租赁OLED透明
  • 如何从零开始搭建公司自动化测试框架?

    搭建的自动化测试框架要包括API测试 UI测试 APP测试三类 以上三类其实可以简化为两类 那就是 1 接口自动化测试框架搭建 2 UI自动化测试框架搭建 没问题 安排 且是手把手教你如何搭建以上两类自动化测试框架 刷到这个问题的测试人员
  • Ubuntu上vscode调试C/C++代码

    这篇文章起初是我看了一个B站的视频 作者讲述了如何在Ubuntu的 环境中通过使用vscode调试C C 代码 这个教程非常好 也非常推荐给大家 但是这个教程有一个局限性 就是他在他的公共号上写的教程非常简略 以至于我想再次看一遍 需要重新
  • 微信小程序引入背景图的三种方法

    1 直接在标签里加上style样式 加上背景图
  • K8s集群组件、flannel网络插件、Pod详解

    文章目录 Kubernetes 1 K8S集群架构 2 角色与功能 3 部署环境要求 Master Node 4 flannel插件 flannel是什么 目的 5 Pod 什么是Pod 为什么要使用Pod Pod的生命周期 Pod的创建过
  • STL源码:lis容器(Qt5.8版本)

    初次学习STL源码 很多语义尚且比较模糊 需待二次学习 源文件结构 主要的实现都在
  • Odoo 16 企业版手册 - CRM (2)

    销售线索 在与客户或组织开展业务之前 可以将销售线索视为第一步 如果个人或组织对您的业务感兴趣 您可以将他们的兴趣转换为您的业务 作为销售线索 稍后可以转换为销售机会 在Odoo CRM的帮助下 可以从各种来源收集线索 通过电话 短信 电子
  • windows下安装git

    一 下载Git安装包 1 打开Git的官方网站 https git scm com 2 找到下载页 https git scm com downloads 3 找到Windows版本下载页面 https git scm com downlo
  • 数据结构复杂度分析

    文章目录 前言 一 什么是复杂度分析 二 为什么要进行复杂度分析 三 如何进行复杂度分析 1 大O表示法 2 复杂度分析法则 四 常用的复杂度级别 1 常数阶O 1 2 线性阶O n 3 平方阶O n 4 对数阶O logn 五 不常见的时
  • golang中多种方式设置时区

    关于我 文章首发 我的博客 欢迎关注 go语言的time Now 返回的是当地时区时间 time Now Format 2006 01 02 15 04 05 time设置自定义时区 var cstSh time LoadLocation
  • c++继承-----继承中构造函数写法

    父类中的属性 调用父类的构造函数初始化 成员函数的方式初始化 子类中的构造函数 必须要调用父类构造函数 必须采用初始化参数列表的方式 子类想构造无参对象 父类必须要写无参构造函数 隐式调用构造函数 class Parent public 我
  • 文字验证码:简单有效的账号安全守卫!

    前言 文字验证码不仅是一种简单易懂的验证方式 同时也是保护您的账号安全的重要工具 通过输入正确的文字组合 您可以有效地确认自己的身份 确保只有真正的用户才能访问您的账号 HTML代码
  • 关于mybatis的resultMap映射VO类

    今天的模块需要用到多表联查 将查到的结果放到一个新的实体类中 而这几张表的主键我需要用到 难过的是多个表的主键名都是 id 这就导致新的实体类中多个表的主键字段名无法区分 最后再查询语句中加入别名以区分多个表的主键 本以为这就可以了 但是在
  • Java 通配符泛型例子

    请看下面的代码 其中会发生错误的代码已经注释掉 并且写明了错误类型 总体来说 泛型通配符就是为了支持多态时父子类 接口扩展类之间的相互转换而生 package test import java util ArrayList import j
  • seaborn学习笔记(三):直方图、条形图、条带图

    html font family sans serif ms text size adjust 100 webkit text size adjust 100 body margin 0 article aside details figc