Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python For Data Science Cheat Sheet, Cheat Sheet of Programming Languages

In this cheat sheet we find a good overview on Python For Data Science, and specifically on: Python Basics, NumPy Basics, SciPy - Linear Algebra, Pandas Basics, Scikit-Learn, Matplotlib, Seaborn, Bokeh

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

ekavir
ekavir 🇺🇸

4.3

(31)

16 documents

Partial preview of the text

Download Python For Data Science Cheat Sheet and more Cheat Sheet Programming Languages in PDF only on Docsity! Selecting List Elements Import libraries >>> import numpy >>> import numpy as np Selective import >>> from math import pi >>> help(str) Python For Data Science Cheat Sheet Python Basics Learn More Python for Data Science Interactively at www.datacamp.com Variable Assignment Strings >>> x=5 >>> x 5 >>> x+2 Sum of two variables 7 >>> x-2 Subtraction of two variables 3 >>> x*2 Multiplication of two variables 10 >>> x**2 Exponentiation of a variable 25 >>> x%2 Remainder of a variable 1 >>> x/float(2) Division of a variable 2.5 Variables and Data Types str() '5', '3.45', 'True' int() 5, 3, 1 float() 5.0, 1.0 bool() True, True, True Variables to strings Variables to integers Variables to floats Variables to booleans Lists >>> a = 'is' >>> b = 'nice' >>> my_list = ['my', 'list', a, b] >>> my_list2 = [[4,5,6,7], [3,4,5,6]] Subset >>> my_list[1] >>> my_list[-3] Slice >>> my_list[1:3] >>> my_list[1:] >>> my_list[:3] >>> my_list[:] Subset Lists of Lists >>> my_list2[1][0] >>> my_list2[1][:2] Also see NumPy Arrays >>> my_list.index(a) >>> my_list.count(a) >>> my_list.append('!') >>> my_list.remove('!') >>> del(my_list[0:1]) >>> my_list.reverse() >>> my_list.extend('!') >>> my_list.pop(-1) >>> my_list.insert(0,'!') >>> my_list.sort() Get the index of an item Count an item Append an item at a time Remove an item Remove an item Reverse the list Append an item Remove an item Insert an item Sort the list Index starts at 0 Select item at index 1 Select 3rd last item Select items at index 1 and 2 Select items after index 0 Select items before index 3 Copy my_list my_list[list][itemOfList] Libraries >>> my_string.upper() >>> my_string.lower() >>> my_string.count('w') >>> my_string.replace('e', 'i') >>> my_string.strip() >>> my_string = 'thisStringIsAwesome' >>> my_string 'thisStringIsAwesome' Numpy Arrays >>> my_list = [1, 2, 3, 4] >>> my_array = np.array(my_list) >>> my_2darray = np.array([[1,2,3],[4,5,6]]) >>> my_array.shape >>> np.append(other_array) >>> np.insert(my_array, 1, 5) >>> np.delete(my_array,[1]) >>> np.mean(my_array) >>> np.median(my_array) >>> my_array.corrcoef() >>> np.std(my_array) Asking For Help >>> my_string[3] >>> my_string[4:9] Subset >>> my_array[1] 2 Slice >>> my_array[0:2] array([1, 2]) Subset 2D Numpy arrays >>> my_2darray[:,0] array([1, 4]) >>> my_list + my_list ['my', 'list', 'is', 'nice', 'my', 'list', 'is', 'nice'] >>> my_list * 2 ['my', 'list', 'is', 'nice', 'my', 'list', 'is', 'nice'] >>> my_list2 > 4 True >>> my_array > 3 array([False, False, False, True], dtype=bool) >>> my_array * 2 array([2, 4, 6, 8]) >>> my_array + np.array([5, 6, 7, 8]) array([6, 8, 10, 12]) >>> my_string * 2 'thisStringIsAwesomethisStringIsAwesome' >>> my_string + 'Innit' 'thisStringIsAwesomeInnit' >>> 'm' in my_string True DataCamp Learn Python for Data Science Interactively Scientific computing Data analysis 2D plotting Machine learning Also see Lists Get the dimensions of the array Append items to an array Insert items in an array Delete items in an array Mean of the array Median of the array Correlation coefficient Standard deviation String to uppercase String to lowercase Count String elements Replace String elements Strip whitespaces Select item at index 1 Select items at index 0 and 1 my_2darray[rows, columns] Install Python Calculations With Variables Leading open data science platform powered by Python Free IDE that is included with Anaconda Create and share documents with live code, visualizations, text, ... Types and Type Conversion String Operations List Operations List Methods Index starts at 0 String Methods String Operations Selecting Numpy Array Elements Index starts at 0 Numpy Array Operations Numpy Array Functions DataCamp Learn Python for Data Science Interactively Saving/Loading Notebooks Working with Different Programming Languages Asking For Help WidgetsPython For Data Science Cheat Sheet Jupyter Notebook Learn More Python for Data Science Interactively at www.DataCamp.com Kernels provide computation and communication with front-end interfaces like the notebooks. There are three main kernels: Installing Jupyter Notebook will automatically install the IPython kernel. Create new notebook Open an existing notebookMake a copy of the current notebook Rename notebook Writing Code And Text Save current notebook and record checkpoint Revert notebook to a previous checkpoint Preview of the printed notebook Download notebook as - IPython notebook - Python - HTML - Markdown - reST - LaTeX - PDF Close notebook & stop running any scripts IRkernel IJulia Cut currently selected cells to clipboard Copy cells from clipboard to current cursor positionPaste cells from clipboard above current cell Paste cells from clipboard below current cellPaste cells from clipboard on top of current cel Delete current cells Revert “Delete Cells” invocation Split up a cell from current cursor position Merge current cell with the one above Merge current cell with the one below Move current cell up Move current cell downAdjust metadata underlying the current notebook Find and replace in selected cells Insert image in selected cells Restart kernel Restart kernel & run all cells Restart kernel & run all cells Interrupt kernel Interrupt kernel & clear all output Connect back to a remote notebook Run other installed kernels Code and text are encapsulated by 3 basic cell types: markdown cells, code cells, and raw NBConvert cells. Edit Cells Insert Cells View Cells Notebook widgets provide the ability to visualize and control changes in your data, often as a control like a slider, textbox, etc. You can use them to build interactive GUIs for your notebooks or to synchronize stateful and stateless information between Python and JavaScript. Toggle display of Jupyter logo and filename Toggle display of toolbar Toggle line numbers in cells Toggle display of cell action icons: - None - Edit metadata - Raw cell format - Slideshow - Attachments - Tags Add new cell above the current one Add new cell below the current one Executing Cells Run selected cell(s) Run current cells down and create a new one below Run current cells down and create a new one above Run all cells Save notebook with interactive widgets Download serialized state of all widget models in use Embed current widgets Walk through a UI tour List of built-in keyboard shortcutsEdit the built-in keyboard shortcuts Notebook help topics Description of markdown available in notebook About Jupyter Notebook Information on unofficial Jupyter Notebook extensions Python help topics IPython help topics NumPy help topics SciPy help topics Pandas help topics SymPy help topics Matplotlib help topics Run all cells above the current cell Run all cells below the current cell Change the cell type of current cell toggle, toggle scrolling and clear current outputstoggle, toggle scrolling and clear all output 1. Save and checkpoint 2. Insert cell below 3. Cut cell 4. Copy cell(s) 5. Paste cell(s) below 6. Move cell up 7. Move cell down 8. Run current cell 9. Interrupt kernel 10. Restart kernel 11. Display characteristics 12. Open command palette 13. Current kernel 14. Kernel status 15. Log out from notebook server Command Mode: Edit Mode: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Copy attachments of current cell Remove cell attachments Paste attachments of current cell Python For Data Science Cheat Sheet Pandas Basics Learn Python for Data Science Interactively at www.DataCamp.com Pandas DataCamp Learn Python for Data Science Interactively Series DataFrame 4 7 -5 3 d c b aA one-dimensional labeled array capable of holding any data type Index Index Columns A two-dimensional labeled data structure with columns of potentially different types The Pandas library is built on NumPy and provides easy-to-use data structures and data analysis tools for the Python programming language. >>> import pandas as pd Use the following import convention: Pandas Data Structures >>> s = pd.Series([3, -5, 7, 4], index=['a', 'b', 'c', 'd']) >>> data = {'Country': ['Belgium', 'India', 'Brazil'], 'Capital': ['Brussels', 'New Delhi', 'Brasília'], 'Population': [11190846, 1303171035, 207847528]} >>> df = pd.DataFrame(data, columns=['Country', 'Capital', 'Population']) Selection >>> s['b'] Get one element -5 >>> df[1:] Get subset of a DataFrame Country Capital Population 1 India New Delhi 1303171035 2 Brazil Brasília 207847528 By Position >>> df.iloc([0],[0]) Select single value by row & 'Belgium' column >>> df.iat([0],[0]) 'Belgium' By Label >>> df.loc([0], ['Country']) Select single value by row & 'Belgium' column labels >>> df.at([0], ['Country']) 'Belgium' By Label/Position >>> df.ix[2] Select single row of Country Brazil subset of rows Capital Brasília Population 207847528 >>> df.ix[:,'Capital'] Select a single column of 0 Brussels subset of columns 1 New Delhi 2 Brasília >>> df.ix[1,'Capital'] Select rows and columns 'New Delhi' Boolean Indexing >>> s[~(s > 1)] Series s where value is not >1 >>> s[(s < -1) | (s > 2)] s where value is <-1 or >2 >>> df[df['Population']>1200000000] Use filter to adjust DataFrame Setting >>> s['a'] = 6 Set index a of Series s to 6 Applying Functions >>> f = lambda x: x*2 >>> df.apply(f) Apply function >>> df.applymap(f) Apply function element-wise Retrieving Series/DataFrame Information >>> df.shape (rows,columns) >>> df.index Describe index >>> df.columns Describe DataFrame columns >>> df.info() Info on DataFrame >>> df.count() Number of non-NA values Getting Also see NumPy Arrays Selecting, Boolean Indexing & Setting Basic Information Summary >>> df.sum() Sum of values >>> df.cumsum() Cummulative sum of values >>> df.min()/df.max() Minimum/maximum values >>> df.idxmin()/df.idxmax() Minimum/Maximum index value >>> df.describe() Summary statistics >>> df.mean() Mean of values >>> df.median() Median of values Dropping >>> s.drop(['a', 'c']) Drop values from rows (axis=0) >>> df.drop('Country', axis=1) Drop values from columns(axis=1) Data Alignment >>> s.add(s3, fill_value=0) a 10.0 b -5.0 c 5.0 d 7.0 >>> s.sub(s3, fill_value=2) >>> s.div(s3, fill_value=4) >>> s.mul(s3, fill_value=3) >>> s3 = pd.Series([7, -2, 3], index=['a', 'c', 'd']) >>> s + s3 a 10.0 b NaN c 5.0 d 7.0 Arithmetic Operations with Fill Methods Internal Data Alignment NA values are introduced in the indices that don’t overlap: You can also do the internal data alignment yourself with the help of the fill methods: Sort & Rank >>> df.sort_index() Sort by labels along an axis >>> df.sort_values(by='Country') Sort by the values along an axis >>> df.rank() Assign ranks to entries Belgium Brussels India New Delhi Brazil Brasília 0 1 2 Country Capital 11190846 1303171035 207847528 Population I/O Read and Write to CSV >>> pd.read_csv('file.csv', header=None, nrows=5) >>> df.to_csv('myDataFrame.csv') Read and Write to Excel >>> pd.read_excel('file.xlsx') >>> pd.to_excel('dir/myDataFrame.xlsx', sheet_name='Sheet1') Read multiple sheets from the same file >>> xlsx = pd.ExcelFile('file.xls') >>> df = pd.read_excel(xlsx, 'Sheet1') >>> help(pd.Series.loc) Asking For Help Read and Write to SQL Query or Database Table >>> from sqlalchemy import create_engine >>> engine = create_engine('sqlite:///:memory:') >>> pd.read_sql("SELECT * FROM my_table;", engine) >>> pd.read_sql_table('my_table', engine) >>> pd.read_sql_query("SELECT * FROM my_table;", engine) >>> pd.to_sql('myDf', engine) read_sql()is a convenience wrapper around read_sql_table() and read_sql_query() Python For Data Science Cheat Sheet Scikit-Learn Learn Python for data science Interactively at www.DataCamp.com Scikit-learn DataCamp Learn Python for Data Science Interactively Loading The Data Also see NumPy & Pandas Scikit-learn is an open source Python library that implements a range of machine learning, preprocessing, cross-validation and visualization algorithms using a unified interface. >>> import numpy as np >>> X = np.random.random((10,5)) >>> y = np.array(['M','M','F','F','M','F','M','M','F','F','F']) >>> X[X < 0.7] = 0 Your data needs to be numeric and stored as NumPy arrays or SciPy sparse matrices. Other types that are convertible to numeric arrays, such as Pandas DataFrame, are also acceptable. Create Your Model Model Fitting Prediction Tune Your Model Evaluate Your Model’s Performance Grid Search Randomized Parameter Optimization Linear Regression >>> from sklearn.linear_model import LinearRegression >>> lr = LinearRegression(normalize=True) Support Vector Machines (SVM) >>> from sklearn.svm import SVC >>> svc = SVC(kernel='linear') Naive Bayes >>> from sklearn.naive_bayes import GaussianNB >>> gnb = GaussianNB() KNN >>> from sklearn import neighbors >>> knn = neighbors.KNeighborsClassifier(n_neighbors=5) Supervised learning >>> lr.fit(X, y) >>> knn.fit(X_train, y_train) >>> svc.fit(X_train, y_train) Unsupervised Learning >>> k_means.fit(X_train) >>> pca_model = pca.fit_transform(X_train) Accuracy Score >>> knn.score(X_test, y_test) >>> from sklearn.metrics import accuracy_score >>> accuracy_score(y_test, y_pred) Classification Report >>> from sklearn.metrics import classification_report >>> print(classification_report(y_test, y_pred)) Confusion Matrix >>> from sklearn.metrics import confusion_matrix >>> print(confusion_matrix(y_test, y_pred)) Cross-Validation >>> from sklearn.cross_validation import cross_val_score >>> print(cross_val_score(knn, X_train, y_train, cv=4)) >>> print(cross_val_score(lr, X, y, cv=2)) Classification Metrics >>> from sklearn.grid_search import GridSearchCV >>> params = {"n_neighbors": np.arange(1,3), "metric": ["euclidean", "cityblock"]} >>> grid = GridSearchCV(estimator=knn, param_grid=params) >>> grid.fit(X_train, y_train) >>> print(grid.best_score_) >>> print(grid.best_estimator_.n_neighbors) >>> from sklearn.grid_search import RandomizedSearchCV >>> params = {"n_neighbors": range(1,5), "weights": ["uniform", "distance"]} >>> rsearch = RandomizedSearchCV(estimator=knn, param_distributions=params, cv=4, n_iter=8, random_state=5) >>> rsearch.fit(X_train, y_train) >>> print(rsearch.best_score_) A Basic Example >>> from sklearn import neighbors, datasets, preprocessing >>> from sklearn.model_selection import train_test_split >>> from sklearn.metrics import accuracy_score >>> iris = datasets.load_iris() >>> X, y = iris.data[:, :2], iris.target >>> X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=33) >>> scaler = preprocessing.StandardScaler().fit(X_train) >>> X_train = scaler.transform(X_train) >>> X_test = scaler.transform(X_test) >>> knn = neighbors.KNeighborsClassifier(n_neighbors=5) >>> knn.fit(X_train, y_train) >>> y_pred = knn.predict(X_test) >>> accuracy_score(y_test, y_pred) Supervised Learning Estimators Unsupervised Learning Estimators Principal Component Analysis (PCA) >>> from sklearn.decomposition import PCA >>> pca = PCA(n_components=0.95) K Means >>> from sklearn.cluster import KMeans >>> k_means = KMeans(n_clusters=3, random_state=0) Fit the model to the data Fit the model to the data Fit to data, then transform it Preprocessing The Data Standardization Normalization >>> from sklearn.preprocessing import Normalizer >>> scaler = Normalizer().fit(X_train) >>> normalized_X = scaler.transform(X_train) >>> normalized_X_test = scaler.transform(X_test) Training And Test Data >>> from sklearn.model_selection import train_test_split >>> X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0) >>> from sklearn.preprocessing import StandardScaler >>> scaler = StandardScaler().fit(X_train) >>> standardized_X = scaler.transform(X_train) >>> standardized_X_test = scaler.transform(X_test) Binarization >>> from sklearn.preprocessing import Binarizer >>> binarizer = Binarizer(threshold=0.0).fit(X) >>> binary_X = binarizer.transform(X) Encoding Categorical Features Supervised Estimators >>> y_pred = svc.predict(np.random.random((2,5))) >>> y_pred = lr.predict(X_test) >>> y_pred = knn.predict_proba(X_test) Unsupervised Estimators >>> y_pred = k_means.predict(X_test) >>> from sklearn.preprocessing import LabelEncoder >>> enc = LabelEncoder() >>> y = enc.fit_transform(y) Imputing Missing Values Predict labels Predict labels Estimate probability of a label Predict labels in clustering algos >>> from sklearn.preprocessing import Imputer >>> imp = Imputer(missing_values=0, strategy='mean', axis=0) >>> imp.fit_transform(X_train) Generating Polynomial Features >>> from sklearn.preprocessing import PolynomialFeatures >>> poly = PolynomialFeatures(5) >>> poly.fit_transform(X) Regression Metrics Mean Absolute Error >>> from sklearn.metrics import mean_absolute_error >>> y_true = [3, -0.5, 2] >>> mean_absolute_error(y_true, y_pred) Mean Squared Error >>> from sklearn.metrics import mean_squared_error >>> mean_squared_error(y_test, y_pred) R² Score >>> from sklearn.metrics import r2_score >>> r2_score(y_true, y_pred) Clustering Metrics Adjusted Rand Index >>> from sklearn.metrics import adjusted_rand_score >>> adjusted_rand_score(y_true, y_pred) Homogeneity >>> from sklearn.metrics import homogeneity_score >>> homogeneity_score(y_true, y_pred) V-measure >>> from sklearn.metrics import v_measure_score >>> metrics.v_measure_score(y_true, y_pred) Estimator score method Metric scoring functions Precision, recall, f1-score and support Python For Data Science Cheat Sheet Matplotlib Learn Python Interactively at www.DataCamp.com Matplotlib DataCamp Learn Python for Data Science Interactively Prepare The Data Also see Lists & NumPy Matplotlib is a Python 2D plotting library which produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. 1 >>> import numpy as np >>> x = np.linspace(0, 10, 100) >>> y = np.cos(x) >>> z = np.sin(x) Show Plot >>> plt.show() Matplotlib 2.0.0 - Updated on: 02/2017 Save Plot Save figures >>> plt.savefig('foo.png') Save transparent figures >>> plt.savefig('foo.png', transparent=True) 6 5 >>> fig = plt.figure() >>> fig2 = plt.figure(figsize=plt.figaspect(2.0)) Create Plot2 Plot Anatomy & Workflow All plotting is done with respect to an Axes. In most cases, a subplot will fit your needs. A subplot is an axes on a grid system. >>> fig.add_axes() >>> ax1 = fig.add_subplot(221) # row-col-num >>> ax3 = fig.add_subplot(212) >>> fig3, axes = plt.subplots(nrows=2,ncols=2) >>> fig4, axes2 = plt.subplots(ncols=3) Customize Plot Colors, Color Bars & Color Maps Markers Linestyles Mathtext Text & Annotations Limits, Legends & Layouts The basic steps to creating plots with matplotlib are: 1 Prepare data 2 Create plot 3 Plot 4 Customize plot 5 Save plot 6 Show plot >>> import matplotlib.pyplot as plt >>> x = [1,2,3,4] >>> y = [10,20,25,30] >>> fig = plt.figure() >>> ax = fig.add_subplot(111) >>> ax.plot(x, y, color='lightblue', linewidth=3) >>> ax.scatter([2,4,6], [5,15,25], color='darkgreen', marker='^') >>> ax.set_xlim(1, 6.5) >>> plt.savefig('foo.png') >>> plt.show() Step 3, 4 Step 2 Step 1 Step 3 Step 6 Plot Anatomy Workflow 4 Limits & Autoscaling >>> ax.margins(x=0.0,y=0.1) Add padding to a plot >>> ax.axis('equal') Set the aspect ratio of the plot to 1 >>> ax.set(xlim=[0,10.5],ylim=[-1.5,1.5]) Set limits for x-and y-axis >>> ax.set_xlim(0,10.5) Set limits for x-axis Legends >>> ax.set(title='An Example Axes', Set a title and x-and y-axis labels ylabel='Y-Axis', xlabel='X-Axis') >>> ax.legend(loc='best') No overlapping plot elements Ticks >>> ax.xaxis.set(ticks=range(1,5), Manually set x-ticks ticklabels=[3,100,-12,"foo"]) >>> ax.tick_params(axis='y', Make y-ticks longer and go in and out direction='inout', length=10) Subplot Spacing >>> fig3.subplots_adjust(wspace=0.5, Adjust the spacing between subplots hspace=0.3, left=0.125, right=0.9, top=0.9, bottom=0.1) >>> fig.tight_layout() Fit subplot(s) in to the figure area Axis Spines >>> ax1.spines['top'].set_visible(False) Make the top axis line for a plot invisible >>> ax1.spines['bottom'].set_position(('outward',10)) Move the bottom axis line outward Figure Axes >>> data = 2 * np.random.random((10, 10)) >>> data2 = 3 * np.random.random((10, 10)) >>> Y, X = np.mgrid[-3:3:100j, -3:3:100j] >>> U = -1 - X**2 + Y >>> V = 1 + X - Y**2 >>> from matplotlib.cbook import get_sample_data >>> img = np.load(get_sample_data('axes_grid/bivariate_normal.npy')) >>> fig, ax = plt.subplots() >>> lines = ax.plot(x,y) Draw points with lines or markers connecting them >>> ax.scatter(x,y) Draw unconnected points, scaled or colored >>> axes[0,0].bar([1,2,3],[3,4,5]) Plot vertical rectangles (constant width) >>> axes[1,0].barh([0.5,1,2.5],[0,1,2]) Plot horiontal rectangles (constant height) >>> axes[1,1].axhline(0.45) Draw a horizontal line across axes >>> axes[0,1].axvline(0.65) Draw a vertical line across axes >>> ax.fill(x,y,color='blue') Draw filled polygons >>> ax.fill_between(x,y,color='yellow') Fill between y-values and 0 Plotting Routines3 1D Data >>> fig, ax = plt.subplots() >>> im = ax.imshow(img, Colormapped or RGB arrays cmap='gist_earth', interpolation='nearest', vmin=-2, vmax=2) 2D Data or Images Vector Fields >>> axes[0,1].arrow(0,0,0.5,0.5) Add an arrow to the axes >>> axes[1,1].quiver(y,z) Plot a 2D field of arrows >>> axes[0,1].streamplot(X,Y,U,V) Plot a 2D field of arrows Data Distributions >>> ax1.hist(y) Plot a histogram >>> ax3.boxplot(y) Make a box and whisker plot >>> ax3.violinplot(z) Make a violin plot >>> axes2[0].pcolor(data2) Pseudocolor plot of 2D array >>> axes2[0].pcolormesh(data) Pseudocolor plot of 2D array >>> CS = plt.contour(Y,X,U) Plot contours >>> axes2[2].contourf(data1) Plot filled contours >>> axes2[2]= ax.clabel(CS) Label a contour plot Figure Axes/Subplot Y-axis X-axis 1D Data 2D Data or Images >>> plt.plot(x, x, x, x**2, x, x**3) >>> ax.plot(x, y, alpha = 0.4) >>> ax.plot(x, y, c='k') >>> fig.colorbar(im, orientation='horizontal') >>> im = ax.imshow(img, cmap='seismic') >>> fig, ax = plt.subplots() >>> ax.scatter(x,y,marker=".") >>> ax.plot(x,y,marker="o") >>> plt.title(r'$sigma_i=15$', fontsize=20) >>> ax.text(1, -2.1, 'Example Graph', style='italic') >>> ax.annotate("Sine", xy=(8, 0), xycoords='data', xytext=(10.5, 0), textcoords='data', arrowprops=dict(arrowstyle="->", connectionstyle="arc3"),) >>> plt.plot(x,y,linewidth=4.0) >>> plt.plot(x,y,ls='solid') >>> plt.plot(x,y,ls='--') >>> plt.plot(x,y,'--',x**2,y**2,'-.') >>> plt.setp(lines,color='r',linewidth=4.0) >>> import matplotlib.pyplot as plt Close & Clear >>> plt.cla() Clear an axis >>> plt.clf() Clear the entire figure >>> plt.close() Close a window
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved