import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101) })
plt.plot( 'x', 'y', data=df, linestyle='none', marker='o')
plt.annotate(
# Labeling and coordination
'This point is interesting!', xy=(25, 50), xytext=(0, 80),
# Custom arrows
arrowprops=dict(facecolor='black', shrink=0.05)
)
plt.show()
import matplotlib.patches as patches
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101) })
my_dpi=96
fig1 = plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
ax1 = fig1.add_subplot(111)
ax1.plot( 'x', 'y', data=df, linestyle='none', marker='o')
ax1.add_patch(
patches.Rectangle(
(20, 25), # (x,y)
50, # Width
50, # Height
# have access to “ angle ” Add rotation
alpha=0.3, facecolor="red", edgecolor="black", linewidth=3, linestyle='solid'
)
)
plt.show()
import matplotlib.patches as patches
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101) })
my_dpi=96
fig1 = plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
ax1 = fig1.add_subplot(111)
ax1.plot( 'x', 'y', data=df, linestyle='none', marker='o')
ax1.add_patch(
patches.Circle(
(40, 35), # (x,y)
30, # radius
alpha=0.3, facecolor="green", edgecolor="black", linewidth=1, linestyle='solid'
)
)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101) })
plt.plot( 'x', 'y', data=df, linestyle='none', marker='o')
plt.plot([80, 40], [30, 90], color="skyblue", lw=5, linestyle='solid', label="_not in legend")
plt.show()
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101) })
plt.plot( 'x', 'y', data=df, linestyle='none', marker='o')
plt.axvline(40, color='r')
plt.axhline(40, color='green')
plt.show()
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101) })
plt.plot( 'x', 'y', data=df, linestyle='none', marker='o')
plt.text(40, 00, r'equation: $\sum_{i=0}^\infty x_i$', fontsize=20)
plt.show()
import matplotlib.patches as patches
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101) })
my_dpi=96
fig1 = plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
ax1 = fig1.add_subplot(111, aspect='equal')
ax1.plot( 'x', 'y', data=df, linestyle='none', marker='o')
ax1.add_patch(
patches.Ellipse(
(40, 35), # (x,y)
30, # Width
100, # Height
45, # radius
alpha=0.3, facecolor="green", edgecolor="black", linewidth=1, linestyle='solid'
)
)
plt.show()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*2 })
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
plt.subplot(121)
plt.plot( 'x', 'y', data=df, marker='o', alpha=0.4)
plt.title("A subplot with 2 lines")
plt.subplot(122)
plt.plot( 'x','z', data=df, linestyle='none', marker='o', color="orange", alpha=0.3)
plt.show()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*2 })
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
plt.subplot(211)
plt.plot( 'x', 'y', data=df, marker='o', alpha=0.4)
plt.title("A subplot with 2 lines")
plt.subplot(212)
plt.plot( 'x','z', data=df, linestyle='none', marker='o', color="orange", alpha=0.3)
plt.show()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*10 })
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
fig, axes = plt.subplots(nrows=2, ncols=1, sharex=True, sharey=True)
axes[0].plot( 'x', 'y', data=df, marker='o', alpha=0.4)
axes[1].plot( 'x','z', data=df, linestyle='none', marker='o', color="orange", alpha=0.3)
axes[0].title.set_text('These 2 plots have the same limit for the Y axis')
plt.show()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*2 })
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
plt.subplot(221)
plt.plot( 'x', 'y', data=df, marker='o', alpha=0.4)
plt.subplot(222)
plt.plot( 'x','z', data=df, linestyle='none', marker='o', color="orange", alpha=0.3)
plt.subplot(223)
plt.plot( 'x','z', data=df, linestyle='none', marker='D', color="green", alpha=0.3)
plt.subplot(224)
plt.plot( 'x','z', data=df, marker='o', color="grey", alpha=0.3)
plt.show()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*2 })
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
fig=plt.figure()
plt.subplot(221)
plt.plot( 'x', 'y', data=df, marker='o', alpha=0.4)
plt.title('title of fig A', fontsize=10, color='grey', loc='left', style='italic')
plt.tick_params(labelbottom='off', bottom='off')
plt.subplot(222)
plt.plot( 'x','z', data=df, linestyle='none', marker='o', color="orange", alpha=0.3)
plt.title('title of fig B', fontsize=10, color='grey', loc='left', style='italic')
plt.tick_params(labelbottom='off', bottom='off')
plt.subplot(223)
plt.plot( 'x','z', data=df, linestyle='none', marker='D', color="green", alpha=0.3)
plt.title('title of fig C', fontsize=10, color='grey', loc='left', style='italic')
plt.subplot(224)
plt.plot( 'x','z', data=df, marker='o', color="grey", alpha=0.3)
plt.title('title of fig D', fontsize=10, color='grey', loc='left', style='italic')
plt.suptitle('A title common to my 4 plots', y=1.02)
plt.show()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*2 })
ax1 = plt.subplot2grid((2, 2), (0, 0), colspan=2)
ax1.plot( 'x', 'y', data=df, marker='o', alpha=0.4)
ax2 = plt.subplot2grid((2, 2), (1, 0), colspan=1)
ax2.plot( 'x','z', data=df, marker='o', color="grey", alpha=0.3)
ax3 = plt.subplot2grid((2, 2), (1, 1), colspan=1)
ax3.plot( 'x','z', data=df, marker='o', color="orange", alpha=0.3)
plt.show()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*2 })
ax1 = plt.subplot2grid((2, 4), (0, 0), colspan=4)
ax1.plot( 'x', 'y', data=df, marker='o', alpha=0.4)
ax2 = plt.subplot2grid((2, 4), (1, 0), colspan=3)
ax2.plot( 'x','z', data=df, marker='o', color="grey", alpha=0.3)
ax3 = plt.subplot2grid((2, 4), (1, 3), colspan=1)
ax3.plot( 'x','z', data=df, marker='o', color="orange", alpha=0.3)
plt.show()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*2 })
ax1 = plt.subplot2grid((2, 2), (0, 0), colspan=1)
ax1.plot( 'x', 'y', data=df, marker='o', alpha=0.4)
ax2 = plt.subplot2grid((2, 2), (1, 0), colspan=1)
ax2.plot( 'x','z', data=df, marker='o', color="grey", alpha=0.3)
ax3 = plt.subplot2grid((2, 2), (0, 1), rowspan=2)
ax3.plot( 'x','z', data=df, marker='o', color="orange", alpha=0.3)
plt.show()
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101), 'z': (np.random.randn(100)*15+range(1,101))*2 })
plt.plot( 'x', 'y', data=df, marker='o', color='mediumvioletred')
plt.show()
The blogger opened a new official account , I hope you can scan the code and pay attention , Thank you very much .
This article is from :https://github.com/holtzy/The-Python-Graph-Gallery/blob/master/PGG_notebook.py