天道酬勤,学无止境

insets

在 matplotlib 图形中插入 svg 图像(Insert an svg image in matplotlib figure)

问题 这是我之前在此处发布的帖子的后续内容。 我正在尝试在 matplotlib 图中添加一个 SVG 图像作为插图。 import matplotlib.pyplot as plt import numpy as np from matplotlib.figure import Figure from matplotlib.offsetbox import OffsetImage, AnnotationBbox ax = plt.subplot(111) ax.plot( [1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2 ) arr_img = plt.imread("stinkbug.svg") im = OffsetImage(arr_img) ab = AnnotationBbox(im, (1, 0), xycoords='axes fraction') ax.add_artist(ab) plt.show() 当输入图像为 png 格式时,该代码有效。 但我无法添加保存在 svg 扩展名(图像)中的相同图像。 我收到以下错误 PIL.UnidentifiedImageError: cannot identify image file 编辑:我试图通过 svglib 读取 svg 文件 import

2021-10-31 00:47:01    分类:技术分享    python-3.x   matplotlib   svg   figure   insets

如何在 Java 中设置工具提示的插图?(How can I set the insets of a tooltip in Java?)

问题 我用 HTML 格式的文本创建了一个工具提示,这很好用,但边框和文本之间没有空格。 如何设置 Insets 或 EmptyBorder? 回答1 找到了这篇关于如何更改 Java ToolTip 属性(背景、边框等)的文章。 它侧重于颜色和边框样式,但也许您也可以将这种方法用于边距(插图)。 回答2 这对我有用: import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JToolTip; import javax.swing.border.EmptyBorder; public class tooltipinsets { public static void main(String[] args) { JFrame window = new JFrame(); JLabel lbl = new JLabel("Test") { @Override public JToolTip createToolTip() { return createCustomToolTip(); } }; window.add(lbl); lbl.setToolTipText("<html><b><i>This is the tooltip</i></b></html>"); window.pack()

2021-09-24 01:36:33    分类:技术分享    java   tooltip   insets

Insert an svg image in matplotlib figure

This is a follow-up to my previous post here. I'm trying to add an SVG image in matplotlib figure as inset. import matplotlib.pyplot as plt import numpy as np from matplotlib.figure import Figure from matplotlib.offsetbox import OffsetImage, AnnotationBbox ax = plt.subplot(111) ax.plot( [1, 2, 3], [1, 2, 3], 'go-', label='line 1', linewidth=2 ) arr_img = plt.imread("stinkbug.svg") im = OffsetImage(arr_img) ab = AnnotationBbox(im, (1, 0), xycoords='axes fraction') ax.add_artist(ab) plt.show() The code works when the input image is in png format. But I am not able to add the same image saved in

2021-09-06 11:56:21    分类:问答    python-3.x   matplotlib   svg   figure   insets

How can I set the insets of a tooltip in Java?

I created a Tooltip with a HTML formated text, this works fine, but I have no space between border and text. How can I set Insets or an EmptyBorder?

2021-08-31 21:07:36    分类:问答    java   tooltip   insets

Is it possible to do a “zoom inset” using seaborn?

This example from matplotlib shows how to do an inset. However I am working with seaborn, specifically the kdeplot. sns.kdeplot(y, label='default bw') sns.kdeplot(y, bw=0.5, label="bw: 0.2", alpha=0.6) sns.kdeplot(y, linestyle="--", bw=2, label="bw: 2", alpha=0.6) sns.kdeplot(y, linestyle=":", bw=5, label="bw: 5", alpha=0.6) It so happens that I have a lot of empty space on the right side of the graph and I would like to put a zoomed in inset there to clarify the lower x range. (If need be I could move the legend out as well, but that's besides the point) Is it possible to do that with seaborn

2021-08-12 04:33:26    分类:问答    python-3.x   matplotlib   seaborn   insets

如何更改 R 中子图/插图的背景颜色?(How to change the background colour of a subplot/inset in R?)

问题 我想在 R 中的现有图中添加一个子图。子图(插图)应该具有不同的背景颜色。 我尝试了以下方法: #install.packages("TeachingDemos", dependencies=T) library(package="TeachingDemos") d0 <- data.frame(x = rnorm(150, sd=5), y = rnorm(150, sd=5)) d0_inset <- data.frame(x = rnorm(1500, sd=5), y = rnorm(1500, sd=5)) plot(d0) subplot( fun = plot( d0_inset , col = 2 , pch = '.' , mgp = c(1,0.4,0) , ann = F , cex.axis=0.5 ) , x = grconvertX(c(0.75,1), from='npc') , y = grconvertY(c(0,0.25), from='npc') , type = 'fig' , pars = list( mar = c(1.5,1.5,0,0) + 0.1 , bg = "blue" # this should change the background color ) ) 在subplot()的帮助下,它表示pars :

2021-07-12 18:10:10    分类:技术分享    r   background   plot   subplot   insets

如何设置 JFrame 的插图?(How can I set the insets of a JFrame?)

问题 有没有办法设置JFrame的插图? 我试过了 frame.getContentPane().getInsets().set(10, 10, 10, 10); 和 frame.getInsets().set(10, 10, 10, 10); 但它们似乎都不起作用。 回答1 JPanel contentPanel = new JPanel(); Border padding = BorderFactory.createEmptyBorder(10, 10, 10, 10); contentPanel.setBorder(padding); yourFrame.setContentPane(contentPanel); 所以基本上, contentPanel是框架的主要容器。 回答2 覆盖JFrame的Insets不会解决您的实际问题。 要回答您的问题,您不能设置JFrame的 Insets 。 您应该扩展 JFrame 并覆盖getInsets方法以提供您需要的插入。 回答3 您必须创建一个 LayOutConstraint 对象并设置其 Insets。 就像在下面的示例中,我使用了 GridBagLayout() 并使用了 GridBagConstraint() 对象。 GridBagConstraints c = new GridBagConstraints()

2021-07-11 00:23:48    分类:技术分享    java   swing   jframe   insets

How can I set the insets of a JFrame?

Is there a way to set the insets of a JFrame? I tried frame.getContentPane().getInsets().set(10, 10, 10, 10); and frame.getInsets().set(10, 10, 10, 10); but none of them seem to work.

2021-06-13 21:15:10    分类:问答    java   swing   jframe   insets

放大插图中不同的 x 和 y 比例,matplotlib(Different x and y scale in zoomed inset, matplotlib)

问题 我正在尝试使用 matplotlib 制作插图。 目前,我在如何缩放图像的一部分并插入到 matplotlib 中的同一图中的最后一个答案类似 那里有一个参数可以确定缩放系数。 但是,我想更改 x 轴和 y 轴之间的比例,即我想在 x 轴上放大更多。 (因此在示例中,正方形将映射到插图下方的矩形)。 我如何实现这一目标? 这是一个工作示例: import pylab as pl import numpy as np from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes from mpl_toolkits.axes_grid1.inset_locator import mark_inset x=np.linspace(0,1,100) y=x**2 ax=pl.subplot(1,1,1) ax.plot(x,y) axins = zoomed_inset_axes(ax, 1, loc=2,bbox_to_anchor=(0.2, 0.55),bbox_transform=ax.figure.transFigure) # zoom = 6 axins.plot(x,y) x1, x2= .4, .6 y1,y2 = x1**2,x2**2 axins.set_xlim(x1, x2) axins

2021-06-12 03:51:45    分类:技术分享    python   matplotlib   plot   insets

Java - JPanel with margins and JTextArea inside

I want to create something like this: Main panel has its margins (x), and TextArea in the center of that panel which almost fills up the panel. At the bottom is another panel with custom size (height y), which can be toggled visible and unvisible with some shortcut. Bottom Panel has FlowLayout and few elements. The problem is I have no idea how to do this. BoxLayout has no margins. I tried with GridBagLayout but I doesn't work or I can't understand it enough :( I tried also with setting JTextArea margins textMain.setMargin(new Insets(insetTop, insetLeft, insetBottom, insetRight)); but when

2021-06-04 17:15:31    分类:问答    java   swing   jtextarea   margins   insets