Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

matplotlib plot

import matplotlib.pyplot as plt
fig = plt.figure(1)	#identifies the figure 
plt.title("Y vs X", fontsize='16')	#title
plt.plot([1, 2, 3, 4], [6,2,8,4])	#plot the points
plt.xlabel("X",fontsize='13')	#adds a label in the x axis
plt.ylabel("Y",fontsize='13')	#adds a label in the y axis
plt.legend(('YvsX'),loc='best')	#creates a legend to identify the plot
plt.savefig('Y_X.png')	#saves the figure in the present directory
plt.grid()	#shows a grid under the plot
plt.show()
Comment

how do a plot on matplotlib python

import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(data)
#this is not nessisary but makes your plot more readable
plt.ylabel('y axis means ...')
plt.xlabel('x axis means ...')
Comment

how to plot in python

import matplotlib.pyplot as plt
import numpy as np

# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)

fig, axarr = plt.subplots(2, 2)
fig.suptitle("This Main Title is Nicely Formatted", fontsize=16)

axarr[0, 0].plot(x, y)
axarr[0, 0].set_title('Axis [0,0] Subtitle')
axarr[0, 1].scatter(x, y)
axarr[0, 1].set_title('Axis [0,1] Subtitle')
axarr[1, 0].plot(x, y ** 2)
axarr[1, 0].set_title('Axis [1,0] Subtitle')
axarr[1, 1].scatter(x, y ** 2)
axarr[1, 1].set_title('Axis [1,1] Subtitle')

# Fine-tune figure;
# hide x ticks for top plots and y ticks for right plots

plt.setp([a.get_xticklabels() for a in axarr[0, :]], visible=False)
plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False)


# Tight layout often produces nice results
# but requires the title to be spaced accordingly

fig.tight_layout()
fig.subplots_adjust(top=0.88)

plt.show()


Comment

matplotlib.plot python

x = [1, 2, 3]
>>> y = np.array([[1, 2], [3, 4], [5, 6]])
>>> plot(x, y)
Comment

matplotlib.plot python

x = [1, 2, 3]
>>> y = np.array([[1, 2], [3, 4], [5, 6]])
>>> plot(x, y)
Comment

how to plot using matplotlib

import matplotlib
matplotlib.rc('text',usetex=True)
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np

text = 'egin{tabular}{|c|c|}hline1&2\hline3&4\hlineend{tabular}'

fig, ax = plt.subplots(1)

img = ax.imshow(np.zeros((10,10)), cmap=plt.cm.gray)
txt = ax.text( 4.5,
          4.5,
          text,
          fontsize=24,
          ha='center',
          va='center',
          bbox=dict(alpha=0))

fig.canvas.draw()
bbox = txt.get_bbox_patch()
xmin = bbox.get_window_extent().xmin
xmax = bbox.get_window_extent().xmax
ymin = bbox.get_window_extent().ymin
ymax = bbox.get_window_extent().ymax

xmin, ymin = fig.transFigure.inverted().transform((xmin, ymin))
xmax, ymax = fig.transFigure.inverted().transform((xmax, ymax))

dx = xmax-xmin
dy = ymax-ymin

# The bounding box vals can be tweaked manually here.
rect = Rectangle((xmin-0.02,ymin-0.01), dx+0.04, dy+0.05, fc='w', transform=fig.transFigure)

ax.add_patch(rect)
fig.canvas.draw()
ax.axis('off')
plt.savefig('ok.png',bbox_inches='tight')




Comment

pyplot.plot

plot([x], y, [fmt], *, data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
Comment

PREVIOUS NEXT
Code Example
Python :: django model get field verbose name 
Python :: How to count a specific number in a python list? 
Python :: clean consol python 
Python :: uninstall python3 from source on centos 7 
Python :: how to return a missing element in python 
Python :: wav file to array python 
Python :: nltk bigrams 
Python :: windows how to store filepath as variabley python 
Python :: python: convert variable as character 
Python :: ordenar lista python 
Python :: swapping variables in python 
Python :: gpt-3 tokenizer python3 
Python :: how to get the realpath with python 
Python :: how to add array in python 
Python :: seaborn color palette python 
Python :: python switch columns order csv 
Python :: delete variable python 
Python :: is in python 
Python :: pip install pandas Getting requirements to build wheel 
Python :: pyton do while loop+ 
Python :: mkdir if not exists python 
Python :: restrict ticks to integers matplotlib 
Python :: python sum of a subset 
Python :: len in python 
Python :: How to Get the Union of Sets in Python 
Python :: Python3 seconds to datetime 
Python :: python override string class 
Python :: python list deep copy 
Python :: Check if file already existing 
Python :: python split 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =