[Matplotlib] Data Representation

Goto: https://plot.ly/python/#3d-charts【丰富的作图资源】

 



 

In [1]:
from pylab import plt
plt.style.use('seaborn')
import matplotlib as mpl
mpl.rcParams['font.family'] = 'serif'
 

In [2]:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
 

In [3]:
np.random.seed(1000)
y = np.random.standard_normal(20)
In [4]:
x = range(len(y))
plt.plot(x, y)
# tag: matplotlib_0
# title: Plot given x- and y-values
Out[4]:
[<matplotlib.lines.Line2D at 0x110382fd0>]
 
[Matplotlib] Data Representation
In [5]:
plt.plot(y)
# tag: matplotlib_1
# title: Plot given data as 1d-array
Out[5]:
[<matplotlib.lines.Line2D at 0x11047f5c0>]
 
[Matplotlib] Data Representation
In [6]:
plt.plot(y.cumsum())
# tag: matplotlib_2
# title: Plot given a 1d-array with method attached
Out[6]:
[<matplotlib.lines.Line2D at 0x1104e6ac8>]
 
[Matplotlib] Data Representation
In [7]:
plt.plot(y.cumsum())
plt.grid(True)  # adds a grid
plt.axis('tight')  # adjusts the axis ranges
# tag: matplotlib_3_a
# title: Plot with grid and tight axes
Out[7]:
(-0.95000000000000007,
 19.949999999999999,
 -2.3228186637490449,
 0.56550858086558653)
 
[Matplotlib] Data Representation
In [8]:
plt.plot(y.cumsum())
plt.grid(True)
plt.xlim(-1, 20)
plt.ylim(np.min(y.cumsum()) - 1,
         np.max(y.cumsum()) + 1)
# tag: matplotlib_3_b
# title: Plot with custom axes limits
Out[8]:
(-3.1915310617211072, 1.4342209788376488)
 
[Matplotlib] Data Representation
In [9]:
plt.figure(figsize=(7, 4))
  # the figsize parameter defines the
  # size of the figure in (width, height)
plt.plot(y.cumsum(), 'b', lw=1.5)
plt.plot(y.cumsum(), 'ro')
plt.grid(True)
plt.axis('tight')
plt.xlabel('index')
plt.ylabel('value')
plt.title('A Simple Plot')
# tag: matplotlib_4
# title: Plot with typical labels
Out[9]:
Text(0.5,1,'A Simple Plot')
 
[Matplotlib] Data Representation
 

In [10]:
np.random.seed(2000)
y = np.random.standard_normal((20, 2)).cumsum(axis=0)
In [11]:
plt.figure(figsize=(7, 4))
plt.plot(y, lw=1.5)
  # plots two lines
plt.plot(y, 'ro')
  # plots two dotted lines
plt.grid(True)
plt.axis('tight')
plt.xlabel('index')
plt.ylabel('value')
plt.title('A Simple Plot')
# tag: matplotlib_5
# title: Plot with two data sets
Out[11]:
Text(0.5,1,'A Simple Plot')
 
[Matplotlib] Data Representation
In [12]:
plt.figure(figsize=(7, 4))
plt.plot(y[:, 0], lw=1.5, label='1st')
plt.plot(y[:, 1], lw=1.5, label='2nd')
plt.plot(y, 'ro')
plt.grid(True)
plt.legend(loc=0)
plt.axis('tight')
plt.xlabel('index')
plt.ylabel('value')
plt.title('A Simple Plot')
# tag: matplotlib_6
# title: Plot with labeled data sets
Out[12]:
Text(0.5,1,'A Simple Plot')
 
[Matplotlib] Data Representation

相关文章:

  • 2021-06-28
  • 2021-12-27
  • 2021-08-23
  • 2021-09-20
  • 2021-06-14
  • 2021-08-24
  • 2021-10-11
  • 2021-11-11
猜你喜欢
  • 2021-11-02
  • 2021-10-11
  • 2021-11-10
  • 2021-08-06
  • 2021-07-25
  • 2022-12-23
  • 2021-08-05
相关资源
相似解决方案