Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date PyPlot-棘手的轴颜色和标签问题_Date_Pandas_Matplotlib_Plot_Yaxis - Fatal编程技术网

Date PyPlot-棘手的轴颜色和标签问题

Date PyPlot-棘手的轴颜色和标签问题,date,pandas,matplotlib,plot,yaxis,Date,Pandas,Matplotlib,Plot,Yaxis,我对Matplotlib相当陌生。这个数字背后的想法是绘制温度的高低。我遇到了xaxis和right yaxis的麻烦 对于xaxis,字体的颜色不想更改,即使我调用勾选参数(labelcolor='.\b6b6b6')。此外,日期应仅从1月到12月。由于未知原因,Matplotlib正在预加一个额外的Dec并附加一个额外的Jan,导致文本超出图形的脊椎边界。我想取消这些额外的月份 对于正确的yaxis,我不确定我是否正确理解子地块的使用。我想将左侧轴的˚C温度转换为˚F,并将转换后的温度用于辅

我对Matplotlib相当陌生。这个数字背后的想法是绘制温度的高低。我遇到了xaxis和right yaxis的麻烦

对于xaxis,字体的颜色不想更改,即使我调用
勾选参数(labelcolor='.\b6b6b6')
。此外,日期应仅从1月到12月。由于未知原因,Matplotlib正在预加一个额外的Dec并附加一个额外的Jan,导致文本超出图形的脊椎边界。我想取消这些额外的月份

对于正确的yaxis,我不确定我是否正确理解子地块的使用。我想将左侧轴的˚C温度转换为˚F,并将转换后的温度用于辅助轴

这里有一些代码来重现与我得到的类似的东西。

若要更改次要标签的颜色,请在
ax1.xaxis.set_minor_格式化程序(dates.DateFormatter('%b'))之后放置以下代码。


我正试图复制你的情节,看看我是否能帮上忙。。。您能否将
t_mins
t_maxs
的定义添加到示例代码中?您的代码不工作
ValueError:传递值的形状是(2,20),索引暗示(2,365)
您可以
ax.set_xticks
设置xticks,但是我有一种感觉,您可能希望
ax1。设置\u xlim
以限制x上显示的值-axis@Cheng,我已经更正了代码并对其进行了测试,以确保其正常工作。t_mins/t_maxs是遗留代码,已被更正。这太棒了。我还了解了如何使用左y轴以˚F创建右y轴。您只需应用转换˚F=(˚C*9/5)+32即可。因此,如果您有一列临时值,您将使用广播并说,
faren\u vals=(摄氏度*9/5)+32
,那么摄氏度列中的所有单元格都将被转换。然后使用
set_ylim(faren_vals)
设置右侧y轴限制。
import numpy as np
import pandas as pd
import matplotlib as mpl 
import matplotlib.pyplot as plt
import matplotlib.dates as dates
import matplotlib.ticker as ticker

# generate some data to plot
highs = np.linspace(0, 40, 365) # these numbers will escalate instead of fluctuate, but the problem with the axes will still be the same.
lows = np.linspace(-40, 0, 365)

date_rng = pd.date_range('1/1/2015', '12/31/2015', freq='D')

data = {'highs': highs, 'lows': lows}
to_plot = pd.DataFrame(data, index=date_rng)

fig, ax = plt.subplots()

# plot the basic data
lines = ax.plot(date_rng, to_plot['lows'], '-',
                date_rng, to_plot['highs'], '-')

# get the axes reference
ax1 = plt.gca()

# fill in between the lines
ax1.fill_between(date_rng,
                to_plot['lows'], to_plot['highs'],
                facecolor='#b6b6b6', # gradient fillbetween
                alpha=.2)

# set the xaxis to only 12 months and space the names.
ax1.xaxis.set_major_locator(dates.MonthLocator())
ax1.xaxis.set_minor_locator(dates.MonthLocator(bymonthday=15, interval=1))

ax1.xaxis.set_major_formatter(ticker.NullFormatter())
ax1.xaxis.set_minor_formatter(dates.DateFormatter('%b'))

for tick in ax1.xaxis.get_minor_ticks():
    tick.tick1line.set_markersize(0)
    tick.tick2line.set_markersize(0)
    tick.label1.set_horizontalalignment('center')

# add a right y axis and set all yaxis properties
ax1.set_ylim([-50, 50])

# change the color and sizes scheme 
info_colors = '#b6b6b6'
bold_colors = '#777777'

# graph lines
ax1.lines[0].set_color('#e93c00') # top redish orange
ax1.lines[1].set_color('#009ae9') # btm blue
plt.setp(lines, lw=.8, alpha=1)

# spines
ax.spines['top'].set_visible(False)
for pos in ['bottom', 'right', 'left']:
    ax.spines[pos].set_edgecolor(info_colors)

# set the title
plt.title('Record Temps, 2005-15: Ann Arbour, MI', fontsize=10, color=bold_colors)

# ticks
ax1.tick_params(axis='both', color=info_colors, labelcolor=info_colors, length=5, direction='out', pad=7, labelsize=8)

# add a legend and edit its properties
leg = plt.legend(['Highs','Lows'], frameon=False, loc=0, fontsize='small')
for text in leg.get_texts():
    text.set_color(info_colors)
    plt.ylabel('˚C', color=info_colors)

# set extra yaxis label
ax2 = ax.twinx()
ax2.set_ylabel('˚F', color=info_colors)
ax2.tick_params('y', colors=info_colors)
ax1.xaxis.set_tick_params(which='minor', colors=info_colors)