import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
# # First create some toy data:
x = np.linspace(0, 2*np.pi, 400)
y = np.sin(x**2)# # # Create just a figure and only one subplot# fig, ax = plt.subplots()# # ax.plot(x, y)# ax.set_title('Simple plot')# # Create two subplots and unpack the output array immediately# f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)# ax1.plot(x, y)# ax1.set_title('Sharing Y axis')# ax2.scatter(x, y)# # Create four polar axes and access them through the returned array# fig, axs = plt.subplots(2, 2, subplot_kw=dict(projection="polar"))# axs[0, 0].plot(x, y)# axs[1, 1].scatter(x, y)# # Share a X axis with each column of subplots# f, axs=plt.subplots(2, 2, sharex='col')# print(axs)# ax1.plot(x, y)# ax1.set_title('Sharing Y axis')# ax2.scatter(x, y)# # Share a Y axis with each row of subplots# plt.subplots(2, 2, sharey='row')# # Share both X and Y axes with all subplots# plt.subplots(2, 2, sharex='all', sharey='all')# # Note that this is the same as# plt.subplots(2, 2, sharex=True, sharey=True)# # Create figure number 10 with a single subplot# # and clears it if it already exists.
fig, ax = plt.subplots(num=10, clear=True)
plt.show()
import numpy as np
b = np.matrix([[1, 2], [3, 4]])
print(b)
b_asarray = np.asarray(b)
print(b_asarray)
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
np.random.seed(19680801)# seed the random number generator.
data ={'a': np.arange(50),
'c': np.random.randint(0, 50, 50),
'd': np.random.randn(50)}
data['b']= data['a'] + 10 * np.random.randn(50)
print(data['b'])
print(data['a'])
data['d']= np.abs(data['d']) * 100
print(data)
fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained')
ax.scatter('a', 'b', c='c', s='d', data=data)
ax.set_xlabel('entry a')
ax.set_ylabel('entry b')
plt.show()
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
def my_plotter(ax:plt.axes, data1, data2, param_dict):
"""
A helper function to make a graph.
"""
out = ax.plot(data1, data2, **param_dict)return out
data1, data2, data3, data4 = np.random.randn(4, 100)# make 4 random data sets
fig, (ax1, ax2)= plt.subplots(1, 2, figsize=(5, 2.7))
my_plotter(ax1, data1, data2, {'marker':'x'})
my_plotter(ax2, data3, data4, {'marker':'o'})ran=np.random.randn(4, 100)
fig, ax = plt.subplots(figsize=(5, 2.7))
x = np.arange(len(data1))
ax.plot(x, np.cumsum(data1), color='blue', linewidth=3, linestyle='--')
l, = ax.plot(x, np.cumsum(data2), color='orange', linewidth=2)
l.set_linestyle(':')
fig, ax = plt.subplots(figsize=(5, 2.7))
ax.scatter(data1, data2, s=2, facecolor='C0', edgecolor='k')
fig, ax = plt.subplots(figsize=(5, 2.7))
ax.plot(data1, 'd', label='data1')
ax.plot(data2, 'd', label='data2')
ax.plot(data3, 'v', label='data3')
ax.plot(data4, 's', label='data4')
ax.legend()
mu, sigma =115, 15
x = mu + sigma * np.random.randn(10000)
print(x)
fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained')# the histogram of the data
n, bins, patches = ax.hist(x, 50, density=1, facecolor='C0', alpha=0.75)
ax.set_xlabel('Length [cm]')
ax.set_ylabel('Probability')
ax.set_title('Aardvark lengths\n (not really)')
ax.text(75, .025, r'$\mu=115,\ \sigma=15$')
ax.axis([55, 175, 0, 0.03])
ax.grid(True)
plt.show()
import numpy as np
import pandas as pd
s=pd.Series([1,3,1,np.nan,6,8])
print(s)
import numpy as np
import pandas as pd
dates=pd.date_range("20130101",periods=6)
print(dates)