8000 Improve linestyles example by thoo · Pull Request #12586 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 9 commits into from
Oct 30, 2018
Merged

Improve linestyles example #12586

merged 9 commits into from
Oct 30, 2018

Conversation

thoo
Copy link
Contributor
@thoo thoo commented Oct 21, 2018

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 rewrite linestyles example.


# Reverse the list so that plots and linestyles are in same order.
linestyles = OrderedDict(linestyles[::-1])

plt.figure(figsize=(10, 6))
Copy link
Member

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()

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.
Copy link
Member

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*.
Copy link
Member

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.

@story645
Copy link
Member

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?

@QuLogic QuLogic changed the title Linestyles Improve linestyles example Oct 23, 2018
@thoo
Copy link
Contributor Author
thoo commented Oct 25, 2018

@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
Copy link
Member

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 '-'
Copy link
Member

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?

@thoo
Copy link
Contributor Author
thoo commented Oct 26, 2018

@QuLogic Done. Thanks.

@jklymak
Copy link
Member
jklymak commented Oct 26, 2018

@thoo, this needs to pass CI obviously...

@thoo
Copy link
Contributor Author
thoo commented Oct 27, 2018

@jklymak All tests are passed except Azure which I need azure-pipelines.yml'.



plt.figure(figsize=(10, 6))
ax = plt.subplot(1, 1, 1)
def simple_plot(ax, linestyles):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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]},
Copy link
Member

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))),
Copy link
Member

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)
Copy link
Member
@timhoffm timhoffm Oct 28, 2018

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*
Copy link
Member
@timhoffm timhoffm Oct 28, 2018

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`.

Copy link
Member
@QuLogic QuLogic Oct 28, 2018

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.

@timhoffm timhoffm dismissed their stale review October 29, 2018 20:50

Comments handled.

Copy link
Member
@timhoffm timhoffm left a 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.

@timhoffm timhoffm merged commit 9fa3e60 into matplotlib:master Oct 30, 2018
@QuLogic QuLogic added this to the v3.1 milestone Oct 30, 2018
thoo added a commit to thoo/matplotlib that referenced this pull request Nov 3, 2018
* '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
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0