Movatterモバイル変換


[0]ホーム

URL:


Menu
×
Sign In
+1 Get Certified For Teachers Spaces Plus Get Certified For Teachers Spaces Plus
   ❮     
     ❯   

Python Tutorial

Python HOMEPython IntroPython Get StartedPython SyntaxPython CommentsPython VariablesPython Data TypesPython NumbersPython CastingPython StringsPython BooleansPython OperatorsPython ListsPython TuplesPython SetsPython DictionariesPython If...ElsePython MatchPython While LoopsPython For LoopsPython FunctionsPython LambdaPython ArraysPython OOPPython Classes/ObjectsPython InheritancePython IteratorsPython PolymorphismPython ScopePython ModulesPython DatesPython MathPython JSONPython RegExPython PIPPython Try...ExceptPython String FormattingPython User InputPython VirtualEnv

File Handling

Python File HandlingPython Read FilesPython Write/Create FilesPython Delete Files

Python Modules

NumPy TutorialPandas TutorialSciPy TutorialDjango Tutorial

Python Matplotlib

Matplotlib IntroMatplotlib Get StartedMatplotlib PyplotMatplotlib PlottingMatplotlib MarkersMatplotlib LineMatplotlib LabelsMatplotlib GridMatplotlib SubplotMatplotlib ScatterMatplotlib BarsMatplotlib HistogramsMatplotlib Pie Charts

Machine Learning

Getting StartedMean Median ModeStandard DeviationPercentileData DistributionNormal Data DistributionScatter PlotLinear RegressionPolynomial RegressionMultiple RegressionScaleTrain/TestDecision TreeConfusion MatrixHierarchical ClusteringLogistic RegressionGrid SearchCategorical DataK-meansBootstrap AggregationCross ValidationAUC - ROC CurveK-nearest neighbors

Python DSA

Python DSALists and ArraysStacksQueuesLinked ListsHash TablesTreesBinary TreesBinary Search TreesAVL TreesGraphsLinear SearchBinary SearchBubble SortSelection SortInsertion SortQuick SortCounting SortRadix SortMerge Sort

Python MySQL

MySQL Get StartedMySQL Create DatabaseMySQL Create TableMySQL InsertMySQL SelectMySQL WhereMySQL Order ByMySQL DeleteMySQL Drop TableMySQL UpdateMySQL LimitMySQL Join

Python MongoDB

MongoDB Get StartedMongoDB Create DBMongoDB CollectionMongoDB InsertMongoDB FindMongoDB QueryMongoDB SortMongoDB DeleteMongoDB Drop CollectionMongoDB UpdateMongoDB Limit

Python Reference

Python OverviewPython Built-in FunctionsPython String MethodsPython List MethodsPython Dictionary MethodsPython Tuple MethodsPython Set MethodsPython File MethodsPython KeywordsPython ExceptionsPython Glossary

Module Reference

Random ModuleRequests ModuleStatistics ModuleMath ModulecMath Module

Python How To

Remove List DuplicatesReverse a StringAdd Two Numbers

Python Examples

Python ExamplesPython CompilerPython ExercisesPython QuizPython ServerPython SyllabusPython Study PlanPython Interview Q&APython BootcampPython CertificatePython Training

MatplotlibMarkers


Markers

You can use the keyword argumentmarker to emphasize each point with a specified marker:

Example

Mark each point with a circle:

import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o')
plt.show()

Result:

Try it Yourself »

Example

Mark each point with a star:

...
plt.plot(ypoints, marker = '*')
...

Result:

Try it Yourself »


Marker Reference

You can choose any of these markers:

MarkerDescription
'o'CircleTry it »
'*'StarTry it »
'.'PointTry it »
','PixelTry it »
'x'XTry it »
'X'X (filled)Try it »
'+'PlusTry it »
'P'Plus (filled)Try it »
's'SquareTry it »
'D'DiamondTry it »
'd'Diamond (thin)Try it »
'p'PentagonTry it »
'H'HexagonTry it »
'h'HexagonTry it »
'v'Triangle DownTry it »
'^'Triangle UpTry it »
'<'Triangle LeftTry it »
'>'Triangle RightTry it »
'1'Tri DownTry it »
'2'Tri UpTry it »
'3'Tri LeftTry it »
'4'Tri RightTry it »
'|'VlineTry it »
'_'HlineTry it »

Format Stringsfmt

You can also use theshortcut string notation parameter to specify the marker.

This parameter is also calledfmt, and is written with this syntax:

marker|line|color

Example

Mark each point with a circle:

import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, 'o:r')
plt.show()

Result:

Try it Yourself »

The marker value can be anything from the Marker Reference above.

The line value can be one of the following:

Line Reference

Line SyntaxDescription
'-'Solid lineTry it »
':'Dotted lineTry it »
'--'Dashed lineTry it »
'-.'Dashed/dotted lineTry it »

Note: If you leave out theline value in the fmt parameter, no line will be plotted.

The short color value can be one of the following:

Color Reference

Color SyntaxDescription
'r'RedTry it »
'g'GreenTry it »
'b'BlueTry it »
'c'CyanTry it »
'm'MagentaTry it »
'y'YellowTry it »
'k'BlackTry it »
'w'WhiteTry it »

Marker Size

You can use the keyword argumentmarkersize or the shorter version,ms to set the size of the markers:

Example

Set the size of the markers to 20:

import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o', ms = 20)
plt.show()

Result:

Try it Yourself »

Marker Color

You can use the keyword argumentmarkeredgecolor or the shortermec to set the color of theedge of the markers:

Example

Set the EDGE color to red:

import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o', ms = 20, mec = 'r')
plt.show()

Result:

Try it Yourself »

You can use the keyword argumentmarkerfacecolor or the shortermfc to set the color inside the edge of the markers:

Example

Set the FACE color to red:

import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o', ms = 20, mfc = 'r')
plt.show()

Result:

Try it Yourself »

Useboththemec andmfc arguments to color the entire marker:

Example

Set the color of both theedge and theface to red:

import matplotlib.pyplot as plt
import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o', ms = 20, mec = 'r', mfc = 'r')
plt.show()

Result:

Try it Yourself »

You can also useHexadecimal color values:

Example

Mark each point with a beautiful green color:

...
plt.plot(ypoints, marker = 'o', ms = 20, mec = '#4CAF50', mfc = '#4CAF50')
...

Result:

Try it Yourself »

Or any of the140 supported color names.

Example

Mark each point with the color named "hotpink":

...
plt.plot(ypoints, marker = 'o', ms = 20, mec = 'hotpink', mfc = 'hotpink')
...

Result:

Try it Yourself »

 
Track your progress - it's free!
 

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.


[8]ページ先頭

©2009-2025 Movatter.jp