我想在轴上打印的值不是30000或7000000,而是30K或7M.这意味着为x <= 10 ^ 6添加K(kilo)后缀,为x> = 10 ^ 6添加M(兆)后缀.我怎样才能做到这一点?
当前代码段:
ax = pylab.gca()
formatter = matplotlib.ticker.FormatStrFormatter('%.f')
ax.xaxis.set_major_formatter(formatter)
Run Code Online (Sandbox Code Playgroud) 这个问题(从一个公司名称得到一个符号)已经在雅虎API 的下一个线程中解决了,我发现第一个和第三个答案非常有用.我还注意到第二个答案涉及Google财经,但它使用的是股票代码,而不是公司名称......
不幸的是,我了解到雅虎有时会使用来自证券交易所的不同股票代码.
所以我想做同样的事情 - 也就是说,我给出一个公司名称,我得到它的符号 - 但是使用Google Finance API而不是Yahoo.
那可能吗 ?谢谢
我试图用温度对时间绘制温度值,格式为HH:MM.我能够将xticks设置为每15分钟重复一次,但第一次打勾是第一次(例如04:40).
有没有办法在每小时和同时的四分之一小时(04:45,05:00,05:15等)上移动刻度?我目前的代码如下:
import matplotlib.pyplot as plt
import matplotlib.dates as md
import datetime as dt
## Dummy times and temperatures
time = [dt.datetime(2017,2,15,4,40),dt.datetime(2017,2,15,4,46),dt.datetime(2017,2,15,4,52),dt.datetime(2017,2,15,4,58),dt.datetime(2017,2,15,5,4),dt.datetime(2017,2,15,5,10)]
temp = [7, 8, 9, 10, 11, 12]
## Plot the data
figtemp, ax = plt.subplots(1, 1)
ax.plot(time, temp)
## Set time format and the interval of ticks (every 15 minutes)
xformatter = md.DateFormatter('%H:%M')
xlocator = md.MinuteLocator(interval = 15)
## Set xtick labels to appear every 15 minutes
ax.xaxis.set_major_locator(xlocator)
## Format xtick labels as HH:MM
plt.gcf().axes[0].xaxis.set_major_formatter(xformatter)
Run Code Online (Sandbox Code Playgroud) 我处理模拟数据并且最近一直在使用matplotlib并且遇到了令人烦恼的事情(一个错误?).
我一直允许matplotlib自动设置刻度标签及其类型(科学等),并且通过一些数据我得到了奇怪的科学股票标签.
在搜索分辨率时,我发现你可以调用set_powerlimits((n,m))来设置将使用科学记数法显示的数据限制.但我遇到了这个问题(如果我没记错的话),数据跨越了几个数量级,我的数据也到处都是,所以我需要某种程序化的解决方案,而不是硬解决方案.请参阅:http://matplotlib.org/api/ticker_api.html
下面我列出了示例数据,代码和屏幕截图.
#! /usr/bin/env python
from matplotlib import pyplot as plt
data = [
[1.83186088e-08,0.03275],
[1.07139009e-07,0.03275],
[2.06376627e-07,0.03275],
[3.03918517e-07,0.03275],
[4.06032883e-07,0.03275],
[5.01194017e-07,0.03275],
[6.02195723e-07,0.03275],
[7.03536925e-07,0.03275],
[8.04625154e-07,0.03275],
[9.06401951e-07,0.03275],
[1.00041895e-06,0.03275],
[1.10230745e-06,0.03275],
[1.2042525e-06,0.03275],
[1.30647822e-06,0.03275],
[1.40109887e-06,0.03275],
[1.50380097e-06,0.03275],
[1.60683242e-06,0.03275],
[1.70208505e-06,0.03275],
[1.80545692e-06,0.03275],
[1.90090648e-06,0.03275],
[2.00453092e-06,0.03275],
[2.10018627e-06,0.03275],
[2.20401747e-06,0.03275],
[2.30009359e-06,0.03275],
[2.4043033e-06,0.03275],
[2.50066449e-06,0.03275],
[2.60513728e-06,0.03275],
[2.70165405e-06,0.03275],
[2.80635938e-06,0.03275],
[2.90331342e-06,0.03275],
[3.00021199e-06,0.03275],
[3.10546819e-06,0.03275],
[3.20257899e-06,0.03275],
[3.30032923e-06,0.0327499999],
[3.40612833e-06,0.0327499999],
[3.50401732e-06,0.0327499997],
[3.60153069e-06,0.0327499996],
[3.70700708e-06,0.0327499993],
[3.80456907e-06,0.0327499988],
[3.90259984e-06,0.0327499982],
[4.00084149e-06,0.0327499973],
[4.10700266e-06,0.0327499959],
[4.2047462e-06,0.0327499942],
[4.30209468e-06,0.0327499918],
[4.40018204e-06,0.0327499886],
[4.50712875e-06,0.032749984],
[4.60630591e-06,0.0327499785],
[4.70519881e-06,0.0327499715],
[4.80398305e-06,0.0327499628],
[4.90251297e-06,0.0327499521],
[5.00182752e-06,0.032749939],
[5.10157551e-06,0.0327499232],
[5.20157575e-06,0.0327499043],
[5.30145192e-06,0.0327498822],
[5.40127044e-06,0.0327498565],
[5.500537e-06,0.0327498272],
[5.60773155e-06,0.0327497911],
[5.70660709e-06,0.0327497534],
[5.80610521e-06,0.0327497112],
[5.90651786e-06,0.0327496642],
[6.00749437e-06,0.0327496124], …Run Code Online (Sandbox Code Playgroud) 我正在做一个程序,每秒必须挂一个时钟,主要问题是我是WPF和MVVM的初学者:)
但是否则我的时钟运行起来并不令人耳目一新 我只有时间和日期目的的特殊课程.
这是我的代码:
TimeDate类:
public class TimeDate : ViewModelBase
{
public string SystemTimeHours;
string SystemTimeLong;
string SystemDateLong;
string SystemTimeZoneLong;
string SystemTimeShort;
string SystemDateShort;
string SystemTimeZoneShort;
public void InitializeTimer()
{
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
SystemTimeHours = DateTime.Now.ToString("HH:mm tt");
}
}
Run Code Online (Sandbox Code Playgroud)
视图模型:
public class ViewModel : ViewModelBase
{
public ViewModel()
{
TimeDate td = new TimeDate();
td.InitializeTimer();
HoursTextBox = td.SystemTimeHours;
}
private string _hourstextbox;
public …Run Code Online (Sandbox Code Playgroud) 我有这样的情节::
from bokeh.io import output_file, show
from bokeh.charts import Line
from bokeh.models import FixedTicker
import pandas as pd
output_file('file.html')
data = {'Date shift end': {0: '01/01/16', 1: '01/02/16', 2: '01/03/16',
3: '01/04/16', 4: '01/05/16', 5: '01/06/16',
6: '01/07/16', 7: '01/08/16', 8: '01/09/16',
9: '01/10/16', 10: '01/11/16', 11: '01/12/16',
12: '01/13/16', 13: '01/14/16', 14: '01/15/16',
15: '01/16/16', 16: '01/17/16', 17: '01/18/16',
18: '01/19/16', 19: '01/20/16'},
'Finance_Lbs': {0: 0.0, 1: 92218.080000000002, 2: 469434.14000000001,
3: 513948.95000000001, 4: 578014.71999999997,
5: 432396.69, 6: 573912.75,
7: …Run Code Online (Sandbox Code Playgroud) 我是bokeh的新手,正在尝试在折线图中绘制一些数据。x轴,y轴以及刻度线的大小应与默认值不同。
这是我的代码示例:
from bokeh.plotting import figure, show
from bokeh.models import Legend, LinearAxis
import numpy as np
x = list(range(10))
y = list(range(10))
plot = figure(plot_width=900, plot_height=600)
plot.xaxis.axis_label="xaxis_name"
plot.xaxis.axis_label_text_font_size = "25pt"
plot.xaxis.axis_label_text_font = "times"
plot.xaxis.axis_label_text_color = "black"
plot.yaxis.axis_label="yaxis_name"
plot.yaxis.axis_label_text_font_size = "25pt"
plot.yaxis.axis_label_text_font = "times"
plot.yaxis.axis_label_text_color = "black"
plot.line( x, y, line_width=4, line_color='red', legend="arbitrary_line" )
plot.legend.location = "top_left"
plot.legend.label_text_font_size = "21pt"
plot.legend.label_text_font = "times"
plot.legend.label_text_color = "black"
show(plot)
Run Code Online (Sandbox Code Playgroud)
输出如下所示:

数据是为该示例构成的,但是思想是相同的。请注意,在当前绘图中,x轴标签文本和刻度号之间存在很大的差异。我要设置的大小是打勾标签的大小。任何见识将不胜感激。
在过去一天左右的时间里,我一直在努力解决问题,以找出创建N个并发函数的最佳方法,这些函数在Go中以相同的时间间隔定期调用。我希望能够指定任意数量的功能,让它们全部同时定期运行,并在指定的时间后结束它们。
现在,我有一个可行的解决方案,但是必须为每个并发函数创建一个新的代码。我也不确定如何正确使用sync.WaitGroup,因为我当前的实现导致程序永无休止(只是卡在了wg.Wait()的最后)
我简要地看了一下名为Multitick的自动报价包装器,但不确定如何实现它。也许Multitick可能是这里的解决方案?
func main() {
N := 10
var wg sync.WaitGroup
wg.Add(N)
quit := make(chan struct{})
for i := 0; i < N; i++ {
tick := time.NewTicker(500 * time.Millisecond)
go func(t *time.Ticker) {
for a := range tick.C {
select {
case <-quit:
break
default:
fmt.Println(a) // do something on tick
}
}
wg.Done()
}(tick)
}
time.Sleep(10 * time.Second)
close(quit)
wg.Wait()
}
Run Code Online (Sandbox Code Playgroud)
因此,此解决方案有效,可以以适当的间隔同时执行所有代码,并在10秒后完成,但实际上并没有退出程序,最终挂在wg.Wait()行上。另外,每个并发函数调用都使用自己的代码-我可以通过任何方式使用一个“主”代码来运行所有函数吗?
提前致谢!这是我第一次真正研究Go的并发性。
我在 Flutter 中开发了一个应用程序,其中有很多不同的动画。我想通过分离视图、逻辑(模型 BLoC)和动画来构建我的代码。对于这个问题,我尝试为 StatefulWidget 的不同类中的按钮声明多次相同的动画。
但是,我陷入困境,因为我必须将 TickerProvider 传递给我的动画类,而我没有以正确的方式执行此操作。
构造函数动画类
AppBloc(TickerProvider tickerProvider) {
banimationController = AnimationController(
vsync: tickerProvider,
duration: Duration(milliseconds: 100),
lowerBound: 0,
upperBound: 0.05,
);
}
Run Code Online (Sandbox Code Playgroud)
宣言
AppBloc(this);
Run Code Online (Sandbox Code Playgroud)
我知道这可能不是正确的方法,我编写了这段代码来说明我的问题。
我只想将我的动画声明分离到另一个文件中。
我有一些必须定期运行的功能。我为此使用了股票行情自动收录器。但是,如果股票代码已经在运行,并且时间间隔再次过去,则不应再次执行。
package main
import (
"fmt"
"time"
)
func main() {
ticker := time.NewTicker(3*time.Second)
flag := 0
defer ticker.Stop()
for {
select {
case t := <-ticker.C:
flag = flag + 1
if (flag % 2 ==0 ) {
time.Sleep(time.Second*4)
}
fmt.Println("Current time: ", t)
}
}
}
Run Code Online (Sandbox Code Playgroud)
https://play.golang.org/p/2xV2MYInn4I
在操场上,自动收报机每 3 秒打印一次,但是自动收报机每偶数转一次,作业所花费的时间就比间隔时间要多。我希望它不会运行并删除那些蜱虫。
我该怎么做呢?