Skip to content

DOC: correct linestyle example and reference rcParams #28971

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 1 commit into from
Oct 14, 2024

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Oct 11, 2024

PR summary

Today I had reason to want to know exactly what the "dotted" pattern is and thought this example could have been more helpful. So I

  • added a sentence about configuration by rcParams
  • removed the statement that "dotted" is the same as the pattern (1, 1), since the default rcParam for that is (1, 1.65)
  • in the tuple examples, increased the spacing for "dotted" as it was identical to "densely dotted". I picked 5 to be consistent with the other examples that are not "densely" or "loosely".

PR checklist

@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Oct 11, 2024
@rcomer
Copy link
Member Author

rcomer commented Oct 11, 2024

Renders like this

See also `.Line2D.set_linestyle`.
See also `.Line2D.set_linestyle`. The specific on off sequence of the
"dotted", "dashed" and "dashdot" styles may be configured using
``rcParams["lines.{style}_pattern"]``.
Copy link
Member

Choose a reason for hiding this comment

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

The f-string replacer here is a little mysterious - maybe add an example?

Suggested change
``rcParams["lines.{style}_pattern"]``.
``rcParams["lines.{style}_pattern"]``, eg. `rcParams["lines.dotted_pattern"] = (0, (1, 10))`.

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you think about listing them all out with the :rc: directive? I quite like that we can see the defaults for free, but not sure if it's just too much...

Copy link
Member

Choose a reason for hiding this comment

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

sure, explicit is probably fine.

@rcomer rcomer force-pushed the linestyles branch 2 times, most recently from 536cac4 to 368cb39 Compare October 11, 2024 19:52
@rcomer rcomer marked this pull request as draft October 11, 2024 20:01
@rcomer rcomer marked this pull request as ready for review October 11, 2024 20:37
@rcomer
Copy link
Member Author

rcomer commented Oct 11, 2024

Current iteration

@timhoffm
Copy link
Member

The names and original pattern values are taken over from TikZ in #7087. That somehow got lost in #12586. But I suggest that we keep these relations and possibly also mention that again.

@QuLogic
Copy link
Member

QuLogic commented Oct 11, 2024

While you're here, can you shrink the figure width to under 7 inches? It is currently being scaled down to fit the page content width, which doesn't look good, and I don't see any reason it needs to be this wide specifically.

Possibly add layout='constrained' and then the whitespace on the right will be trimmed, so it will look a similar size as before.

@timhoffm
Copy link
Member

I don't see any reason it needs to be this wide specifically.

Pydata-sphinx-theme has a smaller main content width than our previous website layout. There may well be a number of figures that don't fit anymore.

@QuLogic
Copy link
Member

QuLogic commented Oct 12, 2024

So I double checked on a wide image and the width is actually 896px, which at 100 dpi is just under 9 inches, so it shouldn't be too much different with constrained layout on.

I also went through our sphinx gallery results, and we have 76 images over the limit.

@jklymak
Copy link
Member

jklymak commented Oct 12, 2024

I think sometimes it's fine to shrink an image. Usually instead of shrinking all the fonts and linewidths. In this case I'm sure the figure could simply be smaller.

@rcomer
Copy link
Member Author

rcomer commented Oct 12, 2024

@timhoffm AFAICS the patterns we currently have here still match #7087, but not what is given in that StackExchange answer. I note #7087 is newer than the SE answer, so maybe TikZ changed?

Edit: I found my local file, which seems to match the SE answer.

\tikzset{solid/.style=                   {dash pattern=}}%
\tikzset{dotted/.style=                  {dash pattern=on \pgflinewidth off 2pt}}%
\tikzset{densely dotted/.style=          {dash pattern=on \pgflinewidth off 1pt}}%
\tikzset{loosely dotted/.style=          {dash pattern=on \pgflinewidth off 4pt}}%
\tikzset{dashed/.style=                  {dash pattern=on 3pt off 3pt}}%
\tikzset{densely dashed/.style=          {dash pattern=on 3pt off 2pt}}%
\tikzset{loosely dashed/.style=          {dash pattern=on 3pt off 6pt}}%
\tikzset{dashdotted/.style=              {dash pattern=on 3pt off 2pt on \the\pgflinewidth off 2pt}}%
\tikzset{dash dot/.style=                {dash pattern=on 3pt off 2pt on \the\pgflinewidth off 2pt}}%
\tikzset{densely dashdotted/.style=      {dash pattern=on 3pt off 1pt on \the\pgflinewidth off 1pt}}%
\tikzset{densely dash dot/.style=        {dash pattern=on 3pt off 1pt on \the\pgflinewidth off 1pt}}%
\tikzset{loosely dashdotted/.style=      {dash pattern=on 3pt off 4pt on \the\pgflinewidth off 4pt}}%
\tikzset{loosely dash dot/.style=        {dash pattern=on 3pt off 4pt on \the\pgflinewidth off 4pt}}%
\tikzset{dashdotdotted/.style=           {dash pattern=on 3pt off 2pt on \the\pgflinewidth off 2pt on \the\pgflinewidth off 2pt}}%
\tikzset{densely dashdotdotted/.style=   {dash pattern=on 3pt off 1pt on \the\pgflinewidth off 1pt on \the\pgflinewidth off 1pt}}%
\tikzset{loosely dashdotdotted/.style=   {dash pattern=on 3pt off 4pt on \the\pgflinewidth off 4pt on \the\pgflinewidth off 4pt}}%
\tikzset{dash dot dot/.style=         {dash pattern=on 3pt off 2pt on \the\pgflinewidth off 2pt on \the\pgflinewidth off 2pt}}%
\tikzset{densely dash dot dot/.style=   {dash pattern=on 3pt off 1pt on \the\pgflinewidth off 1pt on \the\pgflinewidth off 1pt}}%
\tikzset{loosely dash dot dot/.style=   {dash pattern=on 3pt off 4pt on \the\pgflinewidth off 4pt on \the\pgflinewidth off 4pt}}%

@rcomer
Copy link
Member Author

rcomer commented Oct 12, 2024

7 inch version

@timhoffm
Copy link
Member

I find it somewhat confusing that the names under "named line styles" are repeated in the "parametrized linestyles " but have different patterns.Obviously, we cannot change the patterns for the matplotlib names. If they are different to the tikz patterns, we should clearly communicate that the above are Matplotlib named linestyles and that the pattern section are examples to reproduce the tikz linestyles.

@rcomer
Copy link
Member Author

rcomer commented Oct 14, 2024

As I understand it, we specify our dash lengths in multiples of linewidth whereas Tikz specifies dash length in points (with only "dot" specified as linewidth). So we can only go so far to match the Tikz styles. We could put the Tikz numbers in and say these are "adapted from Tikz styles"?

Edit: though we also have "long dash with offset" which was added more recently and has nothing to do with Tikz.

@rcomer
Copy link
Member Author

rcomer commented Oct 14, 2024

If the repeated name is the issue, we could also just update the parametrized "dotted" to e.g. "medium dotted".

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.

Ok, let's not overthink this. We can still improve later.

@timhoffm timhoffm added this to the v3.10.0 milestone Oct 14, 2024
@timhoffm timhoffm merged commit 9f8eeba into matplotlib:main Oct 14, 2024
22 checks passed
@rcomer rcomer deleted the linestyles branch October 14, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: examples files in galleries/examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants