-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve linestyles example #12586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve linestyles example #12586
Conversation
|
||
# Reverse the list so that plots and linestyles are in same order. | ||
linestyles = OrderedDict(linestyles[::-1]) | ||
|
||
plt.figure(figsize=(10, 6)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily part of this PR, but since you're touching this code, would you be ok with putting it in OO format:
fig, ax = plt.subplots()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good idea. I will update it with OO format.
*Note*: The dash style can also be configured via `.Line2D.set_dashes` | ||
as shown in :doc:`/gallery/lines_bars_and_markers/line_demo_dash_control` | ||
and passing a list of dash sequences using the keyword *dashes* to the | ||
cycler in :doc:`property_cycle </tutorials/intermediate/color_cycle>`. | ||
""" | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from collections import OrderedDict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can now be removed, since no longer an ordered dict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still using linestyles = OrderedDict(linestyles[::-1])
here. I just reversed the list so that it follows the same order between the list description and the plot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that then, but I don't think you need the ordered dict anyway?
@@ -3,31 +3,44 @@ | |||
Linestyles | |||
========== | |||
|
|||
This examples showcases different linestyles copying those of Tikz/PGF. | |||
This example showcases different linestyles copying those of Tikz/PGF. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be linked to example of Tikz/PGF linestlyes? Otherwise, there's no context.
@@ -3,31 +3,44 @@ | |||
Linestyles | |||
========== | |||
|
|||
This examples showcases different linestyles copying those of Tikz/PGF. | |||
This example showcases different linestyles copying those of Tikz/PGF. | |||
Linestyle can be provided as simple as *solid* , *dotted* or *dashed*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear whether this means I can use the word solid
as an argument to Linestyle or this is talking about lines.
Thanks for the PR! I like the idea of combining the two examples, but maybe they should be left as standalone subplots so that there's a clean example of the symbol denoted way to do things versus the tuple way? |
@story645 Let me know if you want me to change anything. Thanks. |
Linestyle can be provided as simple as *solid* , *dotted*, *dashed* | ||
or *dashdot*. Moreover, the dashing of the line can be controlled by | ||
a dash tuple such as (offset, (on_off_seq)) as mentioned in | ||
`.Line2D.set_linestyle`. For e.g., ``(0, (3, 10, 1, 15))`` means |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g.
already means 'for example'; use 'For example' here.
('dotted', (0, (1, 5))), | ||
('densely dotted', (0, (1, 1))), | ||
linestyle_str = [ | ||
('solid', ('solid')), # Same as (0, ()) or '-' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parentheses around the second element do nothing; are they necessary for something?
@QuLogic Done. Thanks. |
@thoo, this needs to pass CI obviously... |
@jklymak All tests are passed except Azure which I need |
|
||
|
||
plt.figure(figsize=(10, 6)) | ||
ax = plt.subplot(1, 1, 1) | ||
def simple_plot(ax, linestyles): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def simple_plot(ax, linestyles): | |
def plot_linestyles(ax, linestyles): |
ax.annotate(str(linestyle), xy=(0.0, i), xycoords=reference_transform, | ||
xytext=(-6, -12), textcoords='offset points', color="blue", | ||
fontsize=8, ha="right", family="monospace") | ||
fig, ax = plt.subplots(2, 1, gridspec_kw={'height_ratios': [1, 2]}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either use fig, axs =
or fig, (ax1, ax2) =
. ax
is canonically used for a single Axes only.
('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))), | ||
('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))]) | ||
('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep the order loosely, normal, densely.
for i, (name, linestyle) in enumerate(linestyles): | ||
ax.annotate(repr(linestyle), xy=(0.0, i), xycoords=reference_transform, | ||
xytext=(-6, -12), textcoords='offset points', color="blue", | ||
fontsize=8, ha="right", family="monospace") | ||
|
||
X, Y = np.linspace(0, 100, 10), np.zeros(10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move X, Y into the plot function.
@@ -3,50 +3,65 @@ | |||
Linestyles | |||
========== | |||
|
|||
This examples showcases different linestyles copying those of Tikz/PGF. | |||
Linestyle can be provided as simple as *solid* , *dotted*, *dashed* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple linestyles can be defined using the strings "solid", "dotted", "dashed"
or "dashdot". More refined control can be achieved by providing a dash tuple
``(offset, (on_off_seq))``. For example, ``(0, (3, 10, 1, 15))`` means
(3pt line, 10pt space, 1pt line, 15pt space) with no offset. See also
`.Line2D.set_linestyle`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are going to change this line, please remove the dashes between 'pt' and 'line'/'space'; they are not technically required.
@QuLogic thanks. Incorporated in the proposal above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone can merge after CI pass.
* 'master' of https://github.com/matplotlib/matplotlib: (50 commits) Set up CI with Azure Pipelines (matplotlib#12617) Added comment for test. Correctly remove nans when drawing paths with pycairo. Improve docs on Axes limits and direction Extend sphinx Makefile to cleanup completely Remove explicit figure number Update contributing.rst Update contributing.rst DOC: Add badge and link to making PR tutorial Added test cases for scatter plot: 1) empty data/color, 2) pandas.Series with non-0 starting index. TST: mark test_constrainedlayout.py::test_colorbar_location as flaky (matplotlib#12683) Remove deprecation warnings in tests (matplotlib#12686) Make ticks in demo_axes_rgb.py visible Change ipython block to code-block Improve linestyles example (matplotlib#12586) document-textpath Fix index out of bound error for testing first element of iterable. TST: test that get_ticks works FIX: fix error in colorbar.get_ticks not having valid data Replaced warnings.warn with either logging.warnings or cbook._warn_external ...
PR Summary
Close #11908
To combine this two examples: line_styles_reference and linestyles.
in order to reduce redundancy and also explain more about (offset, on-off-dash-seq).
What had done:
Remove
line_styles_reference
example and rewritelinestyles
example.