- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试为 matplotlib.hlines 中的每一行添加标签:
from matplotlib import pyplot as plt
plt.hlines(y=1, xmin=1, xmax=4, label='somelabel1')
plt.hlines(y=2, xmin=2, xmax=5, label='somelabel2')
我需要一个带有两条水平线的图,每条线的“y”轴上都有标签。而不是它,我得到了一个没有标签的图,只有坐标(参见示例图像)。是否可以将每行的标签放入图中?
最佳答案
label
kwarg
用于指定显示在 legend
中的字符串,不一定在行本身。如果您希望标 checkout 现在您的绘图中,您需要使用 text
对象代替
plt.hlines(y=1, xmin=1, xmax=4)
plt.text(4, 1, ' somelabel1', ha='left', va='center')
plt.hlines(y=2, xmin=2, xmax=5)
plt.text(2, 2, 'somelabel2 ', ha='right', va='center')
如果您想要为这些设置特殊的 y 轴标签,则可以使用自定义格式化程序。
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
plt.hlines(y=1, xmin=1, xmax=4)
plt.hlines(y=2, xmin=2, xmax=5)
def formatter(y, pos):
if y == 1:
return 'label1'
elif y == 2:
return 'label2'
else:
return y
plt.gca().yaxis.set_major_formatter(ticker.FuncFormatter(formatter))
关于python - 如何在 matplotlib.hlines 中设置标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43348228/
我想用该方面的人口中位数绘制一条水平方面的线。 我尝试了这种方法,但没有使用以下代码创建虚拟汇总表: require(ggplot2) dt = data.frame(gr = rep(1:2, ea
添加多条 hlines 进行绘图。 xstart 和 xfinsh 值位于 pandas 数据框中 xstart xfinish 0.00 6.30 37.45 43.95 57.16
我有一个带有两个静态 HLine 的条形图,我想为它们添加标签(或图例),以便在图上定义它们。我试过类似的东西: eq = ( sr2.hvplot( kind="bar",
我已经尝试了几个小时来完成这项工作。我尝试使用“python-gantt”包,但没有成功。我也尝试过 plotly(这很漂亮,但我不能在他们的网站上托管我的敏感数据,所以那行不通)。 我的起点是这里的
我有一个折线图,其中包含不同年份和月份的指标。我想为每个月添加一条中线。 library(dplyr) library(lubridate) library(ggplot2) set.seed(52)
假设我有一个简单的 xtable,如下所示: library(xtable) x % latex table generated in R 3.6.0 by xtable 1.8-4 package
我正在尝试以组织模式记录我的时间: ** Bob Johnson, Bob's SEO | subject | time
找了好久都没找到解决办法。我正在用 ggplot2 中的一些水平线循环绘制箱线图。我想出了将线条美学设置“颜色”映射为图例中我想要的名称,以获得线条和箱线图的图例。但是,线条索引值似乎没有更新,并且绘
我有一个看起来像这样的数据框。 > head(df) DGene JGene cdr3_len Sum 1 IGHD1 IGHJ1 0 22 2 IGHD1 IGHJ1
我正在尝试为 matplotlib.hlines 中的每一行添加标签: from matplotlib import pyplot as plt plt.hlines(y=1, xmin=1, xma
我想简单地拥有字符串 '\\ \hline' 在我的程序中。现在我使用了单引号,所以我希望 a = ' \\ \hline' 给我我想要的,反而我得到 irb(main):001:0> a =
我有一个问题。我正在尝试在我的 mplfinance 图表中画线。为此,我有以下代码: levels = [(8531.0, Timestamp('2020-02-27 00:00:00')), (8
使用 geom_tile 函数时,我无法删除矩形之间的空白区域。 df <- data.frame( x = c(seq(2,16,2),seq(17,39,2)), y = c(rep(c(
在一个简单的 latex .tex 文件,我如何为 hline 着色? 我试过了 \hline[color:red] ...和: \hline{color:red} ...但它们不起作用 同样
以 Iris 数据集为例,我可以生成一个带有 facet 的 ggplot。 代码是: library(ggplot2) data(iris) y=iris y$Petal.Width.Range=f
下面的代码是如何工作的: //@version=3 study("My Script", overlay=true) price = (ticker == "EURUSD" ? 1.1600 : 1.
我有一个 pm2_5 数据框数据,我使用 matplotlib 散点图 绘制了这些数据。我想在不同的 y 值 处插入多条水平线,我通过为 y 的每个不同值手动调用 '''ax.axhline''' 函
下面的代码是如何工作的: //@version=3 study("My Script", overlay=true) price = (ticker == "EURUSD" ? 1.1600 : 1.
我有一个 pm2_5 数据框数据,我使用 matplotlib 散点图 绘制了这些数据。我想在不同的 y 值 处插入多条水平线,我通过为 y 的每个不同值手动调用 '''ax.axhline''' 函
在图表中的 100 级添加 axline/hline 后,我正在努力调整我的情节图例。(已添加屏幕截图) 如果有一种方法可以正确运行它,那么图例中不会丢失任何信息,并且可以添加另一个 hline 并将
我是一名优秀的程序员,十分优秀!