小编Ann*_*neS的帖子

如何使用matplotlib显示两个数字?

我在同时绘制两个数字时遇到了一些麻烦,没有在一个图中显示.但根据文档,我编写了代码,只有图一显示.我想也许我失去了一些重要的东西.任何人都可以帮我搞清楚吗?谢谢.(代码中使用的*tlist_first*是一个数据列表.)

plt.figure(1)
plt.hist(tlist_first, bins=2000000, normed = True, histtype ="step", cumulative = True, color = 'g',label = 'first answer')
plt.ylabel('Percentage of answered questions')
plt.xlabel('Minutes elapsed after questions are posted')

plt.axvline(x = 30, ymin = 0, ymax = 1, color = 'r', linestyle = '--', label = '30 min')
plt.axvline(x = 60, ymin = 0, ymax = 1, color = 'c', linestyle = '--', label = '1 hour')
plt.legend()
plt.xlim(0,120)
plt.ylim(0,1) 
plt.show()
plt.close() ### not working either with this line or without …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

65
推荐指数
4
解决办法
15万
查看次数

ValueError("color kwarg每个数据集必须有一种颜色")?

我只是将数据保存到文件中并将其读出然后绘制直方图.然而,虽然我实际上没有改变原始代码,但看起来这个错误.谁能告诉我什么是错的?非常感谢.

这是hist()的代码

f_120 = plt.figure(1)
plt.hist(tfirst_list, bins=6000000, normed = True, histtype ="step", cumulative = True, color = 'g',label = 'first answer')
plt.axvline(x = 30, ymin = 0, ymax = 1, color = 'r', linestyle = '--', label = '30 min')
plt.axvline(x = 60, ymin = 0, ymax = 1, color = 'c', linestyle = '--', label = '1 hour')
plt.legend()

plt.ylabel('Percentage of answered questions')
plt.xlabel('Minutes elapsed after questions are posted')
plt.title('Cumulative histogram: time elapsed \n before questions receive answer (first …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

13
推荐指数
1
解决办法
3万
查看次数

如何在Java Swing TextArea中更改突出显示颜色?并且,更改与突出显示位置对应的文本的开头

问题1:通过使用defaulthighlighter,我可以使聚焦线变为蓝色.现在我想把它换成其他颜色.有谁知道如何更改此参数? - - 解决了

问题2:pos是我想要突出显示的子串的起始索引.我用setCaretPosition(pos); 更新显示内容.但它总是出现在窗口的底部.我希望它在顶部.谁能告诉我如何处理?

我使用一个演示来显示我的问题:

import java.awt.Color;
import java.net.MalformedURLException;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;

public class Test {
    public static void main(final String[] args) throws MalformedURLException {
        SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                init();
            } catch (BadLocationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
}

private static void init() throws BadLocationException {
    JFrame frame = new JFrame();
    final JTextArea textArea …
Run Code Online (Sandbox Code Playgroud)

java swing jtextarea swing-highlighter

10
推荐指数
3
解决办法
2万
查看次数

如何使用正则表达式搜索具有一定数量的出现的字符串?

我正在使用正则表达式来搜索适合我的限制的字符串.例如," HHHHLLLHHHHHLLLLL",我想找到字母H的总出现次数大于8 的字符串.

我尝试构造一个正则表达式,{8,}用于搜索H等于或大于8的出现.但是,它似乎不起作用.

Str1 = '"HHHHLLLHHHHHLLLLL"'
m = re.search(r'regex', Str1).group(0)
Run Code Online (Sandbox Code Playgroud)

有人能给我一些建议吗?谢谢.

python regex

2
推荐指数
2
解决办法
79
查看次数

为什么元组赋值失败?

我试图将新数据分配给现有元组,但它不起作用.实际上我想添加a和b来获得总和,但是只能迭代字符串..

A=[('3', '4'), ('3', '11'), ('8', '10')] 
  print A
for a,b in A:
  a,b = int(a), int(b)+int(a)
print A
Run Code Online (Sandbox Code Playgroud)

结果:

[('3','4'),('3','11'),('8','10')]

[('3','4'),('3','11'),('8','10')]

python

1
推荐指数
1
解决办法
140
查看次数

标签 统计

python ×4

matplotlib ×2

java ×1

jtextarea ×1

regex ×1

swing ×1

swing-highlighter ×1