- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Python 3.x 使用 matplotlib 生成箱线图。
一般:我有一个数据框,我想将其内容创建到一个箱线图中。问题是,跨列的比例不一致; l1 和 l2 需要绘制在与 l3:l5 不同的 Y 轴上。第一个包含 17 列,另外两个各有 1 列。
l1 = [32107.0,20490.0, 32107.0, 22134.0,31564.0, 32107.0, 22134.0, 20732.0, 20490.0, 28406.0]
l2 = [54.4, 40.2, 54.4, 41.1, 49.4, 54.4, 41.1, 37.0, 40.2, 34.2]
l3 = [4595.0, 2164.0, 4595.0, 3500.0, 3733.0, 4595.0, 3500.0, 3214.0, 2164.0, 3388.0]
l4 = [4868.0, 2289.0, 4868.0, 3652.0, 4128.0, 4868.0, 3652.0, 3418.0, 2289.0, 3980.0]
l5 = [3777.0, 1623.0, 3777.0, 2456.0, 3010.0, 3777.0, 2456.0, 2318.0, 1623.0, 2677.0]
df2 = pd.DataFrame(
{'l1' : l1,
'l2' : l2,
'l3': l3,
'l4' : l4,
'l5' : l5})
fig, ax = plt.subplots(figsize=(5, 3))
ax.boxplot(df2[['l1']].transpose())
ax2 = ax.twinx()
ax2.boxplot(df2['l2'], positions = [2])
ax3 = ax.twinx()
ax3.boxplot(df2['l3'], positions = [3])
ax.set_xlim(0, 7)
它不漂亮,但也不是我的完整数据,但结果是一致的;前两列的标签消失了,只剩下最后一个。
我已经尝试了 set_xticks() 和其他一些调用,但我无法到达任何地方。
我确实知道如何偏移 y 轴等等;我基本上挂断了标签的事情。
最佳答案
试试这个来设置你的 xaxis 刻度:
l1 = [32107.0,20490.0, 32107.0, 22134.0,31564.0, 32107.0, 22134.0, 20732.0, 20490.0, 28406.0]
l2 = [54.4, 40.2, 54.4, 41.1, 49.4, 54.4, 41.1, 37.0, 40.2, 34.2]
l3 = [4595.0, 2164.0, 4595.0, 3500.0, 3733.0, 4595.0, 3500.0, 3214.0, 2164.0, 3388.0]
l4 = [4868.0, 2289.0, 4868.0, 3652.0, 4128.0, 4868.0, 3652.0, 3418.0, 2289.0, 3980.0]
l5 = [3777.0, 1623.0, 3777.0, 2456.0, 3010.0, 3777.0, 2456.0, 2318.0, 1623.0, 2677.0]
df2 = pd.DataFrame(
{'l1' : l1,
'l2' : l2,
'l3': l3,
'l4' : l4,
'l5' : l5})
fig, ax = plt.subplots(figsize=(5, 3))
ax.boxplot(df2[['l1']].transpose())
ax2 = ax.twinx()
ax2.boxplot(df2['l2'], positions = [2])
ax3 = ax.twinx()
# ax3.boxplot(df2[['l3','l4','l5']], positions = [3,4,5])
df2[['l3','l4','l5']].plot.box(positions=[3,4,5], ax=ax3)
ax.set_xlim(0, 7)
_ = ax3.xaxis.set_ticks([1,2,3,4,5])
_ = ax3.xaxis.set_ticklabels(['l1','l2','l3','l4','l5'])
输出:
关于python - Matplotlib 多个 Y 轴,xlabels 消失了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53714734/
我的图中有节点,它们的 xlabels 位于它们的左上方。我怎样才能改变这个位置?我希望 xlabels 正好位于节点本身的旁边。 最佳答案 xlp是你想要的属性,但它没有做任何事情。 你不能改变位置
下面的代码在每个循环中绘制了一个图形,我希望将每个矩阵的平均值打印为 x 标签。例如:ave 是 40。我不确定如何将每个图像的 ave 添加到 xlabel。 import matplotlib.p
当我在 IPython 中运行它时: r = (100, 300) b = 100 plt.figure(figsize=(8, 6)) plt.subplot(3,1,1) plt.xlabel('
当我在 IPython 中运行它时: r = (100, 300) b = 100 plt.figure(figsize=(8, 6)) plt.subplot(3,1,1) plt.xlabel('
我正在尝试用文本重命名我的 x 标签并编写以下代码: dow=pd.to_datetime(df1['Dates']).dt.dayofweek Weekdays= ['Monday', 'Tuesd
请问如何设置xlabel的空间?我读过https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlabel.html但我不明白。我使用 matplot
我正在研究全局恐怖主义数据库,并试图绘制各种目标类型的恐怖分子的条形图。我想为每个 xlabel 分配一个代码,并在图表上打印一个图例,显示目标类型的相应代码 到目前为止我还没有找到解决这个问题的办法
在pyplot模块中可以使用xlabel()和ylabel()函数设置x轴y轴的标签。这两个函数的使用方法非常相似。 使用xlabel()设置x轴标签 函数签名为matplotlib.pyplo
我尝试使用 dot 绘制图形,但出现以下问题 节点标签 b与 a 的边缘重叠至 b .有没有办法以某种方式移动这个标签来避免这种情况? 这是我用来生成图像的代码(使用 dot ) digraph A
这是我的代码: var months = ["January", "February", "March", "April", "May", "June", "July", "August", "Se
我不知道我在这里错过了什么。折线图未显示第一个 x 标签: 这是我的代码: new Morris.Line({ element: 'chart_170', data: [ { y: '2015
有什么方法可以将 xLabel(预测标签) 0、1 移动到混淆矩阵的顶部吗?感谢任何帮助。 from sklearn.metrics import accuracy_score plt.figure(
我正在创建一个绘图,我想在坐标轴和标题上放置标签,但它以某种方式忽略了 plt.xlabel : import matplotlib.pyplot as plt import numpy as np
我正在使用 pandas plot 生成堆叠条形图,它与 matplotlib 的行为不同,但日期总是以错误的格式出现,我无法更改它。我还想要图表上的“总计”线。但是当我尝试添加它时,之前的条形图被删
我正在使用 pygraphviz 为我的项目创建图表。我无法弄清楚如何将节点的 xlabel 居中以及如何更改 xlabel 的颜色。 graph.add_node(row[3], color='go
我编写了一个函数来在此处显示一些图表: def plot_price_series(df, ts1, ts2): # price series line graph fig = plt
绘制图形时使用了中文标题,会出现乱码 原因是matplotlib.pyplot在显示时无法找到合适的字体。 先把需要的字体(在系统盘C盘的windows下的fonts目录内)添加到FontP
我无法设置 xlabel的情节当 我用 Pandas 做 scatter地块 在多个子图中 并指定 c颜色属性列。 例如,这很好用:我可以看到 xlabel : import numpy as np
我正在使用 ggplot2 和 facet_grid,输出格式为 PNG。如何在 x 轴标签中写入符号“Angstroms”?我尝试了 xlab("{\305}") 但它为我打印了一个奇怪的符号。 最
我正在使用下面给出的代码使用 ggplot 在同一页面上绘制多个图形。我不想让每个图表都有自己的 xlabel、ylabel、标题和图例描述,我只希望每个页面都有一个这样的图表。我试图找到解决方案,但
我是一名优秀的程序员,十分优秀!