It can be executed with python2.6
+matplotlib (1.4.3)
[^ 1].
[^ 1]: Cannot be executed with matplotlib (1.0.1)
When you want to make the axis a completely different scale when creating a graph.
--From real numbers to time axis on the X axis. --Set the Y axis from 0 to 10 to 0 to 100
This time, in the subplot, after creating the axis, plot the data for ʻax1.twinx (). Twiny () . The plot target is
rand.txt`, which I use every time.
python
$ perl -le 'print rand (10) for 0 .. 99' > rand.txt
replace.py
#!/usr/bin/env python -B
# -*- coding: utf-8 -*-
import sys
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv(sys.argv[1], header=None)
#Axis plot
fig, ax1 = plt.subplots()
ax1.xaxis_date() #X is time series
ax1.set_ylim([0,100]) #Y is 0~100
ax1.grid(True)
ax = ax1.twinx().twiny()
#Data plot
df.plot(ax=ax,xticks=[],yticks=[])
ax.legend().set_visible(False)
ax.grid(False)
fig.subplots_adjust( bottom=0.15, top=0.95,left=0.1, right=0.95)
plt.savefig(sys.argv[2])
python
$ python replace.py rand.txt graph.png
When dealing with time series with matplotlib
, plotting data [^ 2] containing a huge amount of time stamps seems to rot around locators such as dates.MonthLocator
.
[^ 2]: About 10 * 365 * 24 * 60 (hour order).
If you execute it without arguments, it will be a decent picture, but once (once), if you execute it with interval = 4, etc., the grid and xticklabel will be messed up.
In order to avoid that, subtract a huge amount of time stamps appropriately and draw a grid etc. from there [^ 3].
[^ 3]: 10 * 365 * 24 (daily order)
memo
--At the end, do fig.subplots_adjust ()
.
--Plots with pandas
may change the image width without permission, so make a habit of explicitly adjusting.
Recommended Posts