Java - 如何在一段精确的时间内阻止正在运行的线程?(Java - How to block a running thread for an exact amount of time? [closed])
我需要我的主线程阻止特定的时间。 我目前正在研究2D游戏,因为Thread.sleep(2)睡眠时间约为17秒,并且当你移动角色时图形略微滞后,因此它非常滞后。 有时它工作得很好(当我运行应用程序大约10次)时有时并非如此。 我知道Thread.sleep(long milliseconds)方法有一个延迟,但是有什么方法可以避免它或替代方法吗? 我已经尝试过LockSupport.parkNanos((long)2e6),但这并没有改变任何东西。
I need my main Thread to block for a specific amount of time. I am currently working on a 2D game and it's pretty laggy just because the Thread.sleep(2) sleeps for ~17 seconds and when you move the character, graphics are lagging slightly. Sometimes it's working just fine (when I ran the application about 10 times) and sometimes it's not. I know that there is a delay on the Thread.sleep(long milliseconds) method but is there any way to avoid it or an alternative? I already tried LockSupport.parkNanos((long)2e6) but that didn't change anything.
原文:https://stackoverflow.com/questions/35199629
最满意答案
我鼓励你熟悉使用熊猫从数据框中提取定量信息。 例如,你可以做一件简单的事情来获得你正在寻找的值(和其他有用的值):
planets.groupby("method").distance.describe().unstack()
它为每个方法打印一个有用值的表。
或者,如果你只是想要中位数:
planets.groupby("method").distance.median()
I would encourage you to become familiar with using pandas to extract quantitative information from a dataframe. For instance, a simple thing you could to do to get the values you are looking for (and other useful ones) would be:
planets.groupby("method").distance.describe().unstack()
which prints a table of useful values for each method.
Or if you just want the median:
planets.groupby("method").distance.median()
相关问答
更多-
在这方面,Seaborn似乎与matplotlib一样: tips = sns.load_dataset("tips") ax = sns.boxplot(x=tips["total_bill"], whis=[5, 95]) plt.grid(True) plt.boxplot(tips["total_bill"], whis=[5, 95], vert=False) plt.grid(True) 我猜seaborn只是传递给matplotlib方法。 docstring可能是从早期版本的matplo ...
-
正如@mwaskom在下面的评论中指出我的初始答案,可以使用order参数在框之间创建空框位置。 import matplotlib.pyplot as plt import seaborn as sns import pandas as pd import numpy as np x = np.random.choice([1,3,9], size=1001) y = np.random.rand(1001)*(4+np.log(x)) df = pd.DataFrame({"x":x, "y":y}) ...
-
seaborn boxplot的小块(Subplot for seaborn boxplot)[2023-10-03]
我们用子图创建图: f, axes = plt.subplots(1, 2) 其中轴是每个子图的数组。 然后我们用参数ax告诉每个我们想要他们的子图。 sns.boxplot( y="b", x= "a", data=df, orient='v' , ax=axes[0]) sns.boxplot( y="c", x= "a", data=df, orient='v' , ax=axes[1]) 结果是: We create the figure with the subplots: f, ax ... -
使用color参数: import seaborn as sns tips = sns.load_dataset("tips") sns.boxplot(x="day", y="tip", data=tips, color="seagreen") Use the color parameter: import seaborn as sns tips = sns.load_dataset("tips") sns.boxplot(x="day", y="tip", data=tips, color="seag ...
-
如何在Seaborn boxplot中编辑胡须,传单,帽子等属性(How to edit properties of whiskers, fliers, caps, etc. in Seaborn boxplot)[2023-06-15]
您需要编辑存储在ax.lines的Line2D对象。 下面是一个脚本来创建一个箱形图(基于这里的例子),然后根据你的问题中的样式编辑线条和艺术家(即没有填充,所有的线条和标记都是相同的颜色等) 您还可以修复图例中的矩形面片,但需要使用ax.get_legend().get_patches() 。 我还在第二个Axes上绘制了原始的boxplot作为参考。 import matplotlib.pyplot as plt import seaborn as sns fig,(ax1,ax2) = plt.su ... -
交换x和y列名称: import seaborn as sns sns.boxplot(x="weight_cat" y="Height", data=data) 目前,您正在尝试创建一个包含尽可能多的箱图的图表,因为有不同的高度值(24503)。 这对我的数据有用: 编辑 如果要水平显示箱线图,可以使用orient参数提供方向: sns.boxplot(x='Height', y='weight_cat', data=data, orient='h') 请注意,在这种情况下,交换x和y标签(如您的问题 ...
-
有一个matplotlib轴实例ax (因为它是例如由seaborn图返回), ax = sns.boxplot(...) 允许获得标签 ax.get_xticklabels() 将文本从列表中删除的最简单方法是 texts = [t.get_text() for t in ax.get_xticklabels()] 包装文本也可以在运行中完成 texts = [textwrap.fill(t.get_text(), 10) for t in ax.get_xticklabels()] 甚至将文 ...
-
这可能是一个丑陋的解决方案,但它有效,所以谁在乎 fig, ax = plt.subplots(1, 1) boxplot = sns.boxplot(x="Regularisierungsparameter", y="F1", data=data.sort("Regularisierungsparameter"), ax=ax) labels = ['%.5f' % float(t.get_text()) for t in ax.get_xticklabels()] ax.set_xticklabels( ...
-
我鼓励你熟悉使用熊猫从数据框中提取定量信息。 例如,你可以做一件简单的事情来获得你正在寻找的值(和其他有用的值): planets.groupby("method").distance.describe().unstack() 它为每个方法打印一个有用值的表。 或者,如果你只是想要中位数: planets.groupby("method").distance.median() I would encourage you to become familiar with using pandas to ex ...
-
您可以使用sns.boxplot和sns.stripplot函数中的order参数来订购“框”。 下面是一个如何执行此操作的示例(因为“最大到最低”并不完全清楚您的意思,即您希望根据条目对条目进行排序,我假设您要根据总和对它们进行排序对于他们的“距离”值,如果要根据不同的值对它们进行排序,您应该能够编辑解决方案以满足您的需求): import numpy as np import seaborn as sns sns.set(style="ticks", palette="muted", color_cod ...