相关疑难解决方法(0)

matplotlib:格式化轴偏移值到整数或特定数字

我有一个matplotlib图,我正在绘制数据,总是被称为纳秒(1e-9).在y轴上,如果我有数十纳秒的数据,即.在图44e-9中,轴上的值显示为4.4,其中+ 1e-8作为偏移.反正是否强制轴显示带有+ 1e-9偏移的44?

我的x轴也是如此,其中轴显示+ 5.54478e4,我宁愿它显示+55447的偏移(整数,没有小数 - 这里的值是以天为单位).

我尝试过这样的事情:

p = axes.plot(x,y)
p.ticklabel_format(style='plain')
Run Code Online (Sandbox Code Playgroud)

对于x轴,但这不起作用,虽然我可能错误地使用它或误解了文档中的某些东西,有人能指出我正确的方向吗?

谢谢,乔纳森

问题图


我尝试用格式化程序做一些事情,但还没找到任何解决方案......:

myyfmt = ScalarFormatter(useOffset=True)
myyfmt._set_offset(1e9)
axes.get_yaxis().set_major_formatter(myyfmt)
Run Code Online (Sandbox Code Playgroud)

myxfmt = ScalarFormatter(useOffset=True)
myxfmt.set_portlimits((-9,5))
axes.get_xaxis().set_major_formatter(myxfmt)
Run Code Online (Sandbox Code Playgroud)

在旁注中,我实际上对"偏移数"对象实际存在的位置感到困惑...它是主要/次要刻度的一部分吗?

python matplotlib

89
推荐指数
7
解决办法
8万
查看次数

如何更改matplotlib中的x轴,以便没有空格?

因此,目前正在学习如何导入数据并在matplotlib中使用它,我甚至遇到了麻烦,即使我从本书中获得了确切的代码.

在此输入图像描述

这是情节的样子,但我的问题是如何在x轴的开始和结束之间没有空白的地方得到它.

这是代码:

import csv

from matplotlib import pyplot as plt
from datetime import datetime

# Get dates and high temperatures from file.
filename = 'sitka_weather_07-2014.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    #for index, column_header in enumerate(header_row):
        #print(index, column_header)
    dates, highs = [], []
    for row in reader:
        current_date = datetime.strptime(row[0], "%Y-%m-%d")
        dates.append(current_date)

        high = int(row[1])
        highs.append(high)

# Plot data. 
fig = plt.figure(dpi=128, figsize=(10,6))
plt.plot(dates, highs, c='red')


# Format plot.
plt.title("Daily high temperatures, July 2014", fontsize=24) …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

23
推荐指数
1
解决办法
2万
查看次数

如何在Matplotlib中将轴设置为从角开始

这是我绘制的图表:

# MatPlotlib
import matplotlib.pyplot as plt
# Scientific libraries
import numpy as np

plt.figure(1)

points = np.array([(100, 6.09),
                   (111, 8.42),
                   (119, 10.6),
                   (129, 12.5),
                   (139, 14.9),
                   (149, 17.2),
                   (200, 28.9),
                   (250, 40.9),
                   (299, 52.4),
                   (349, 64.7),
                   (400, 76.9)])

# get x and y vectors
x = points[:,0]
y = points[:,1]
# calculate polynomial
z = np.polyfit(x, y, 3)
f = np.poly1d(z)
# calculate new x's and y's
x_new = np.linspace(x[0], x[-1], 50)
y_new = f(x_new)

plt.plot(x,y,'bo', x_new, y_new)

plt.show() …
Run Code Online (Sandbox Code Playgroud)

matplotlib

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

标签 统计

matplotlib ×3

python ×2